<?php

/**
 * Created by PhpStorm.
 * User: benny
 * Date: 05.04.2016
 * Time: 09:22
 */
class Session extends AHDB_Core_RestService
{

    public function get()
    {
        //return 'Test';
    }

    /**
     * Login process - create a new session
     */
    public function post()
    {
        $acc = AHDMN_Ent_Account::getByCredentials(
            $this->params->get( 'credential' ),
            $this->params->get( 'password' )
        );

        if ( is_null( $acc ) )
        {
            $this->throwBadRequest( "Account not found." );
        }

        $userArr = $acc->asArray();
        $userArr[ 'pass' ] = NULL;

        AHDB_Utils_Session::set( 'USER', $userArr );

        return array( 'session_token' => AHDB_Utils_Session::getId() );
    }

    /**
     *
     */
    public function delete()
    {
        AHDB_Utils_Session::set( 'USER', NULL );
    }
}