User management

Discuss everything related to ApPHP MVC Framework. All versions. Any questions related to the Framework developing or using should be posted to this forum.

Moderators: ne_moj, alexmst, zewa, vadimako, ne_moj, alexmst, zewa, vadimako

Jonathan
Newbie
Newbie
Posts: 7
Joined: Jul 16th, '13, 08:56

User management

Postby Jonathan » Jul 16th, '13, 09:08

Hello guys.
Someone was creating user management with apphp framework? It's realizable? If yes then someone can show example? ;)

PS I wrote some little components, widgets and new helpers but idk will be enough this.

administrator
Site Admin
Site Admin
Posts: 5990
Joined: Jan 7th, '09, 23:18
Contact:

Re: User management

Postby administrator » Jul 17th, '13, 05:24

Hi!

Yes, we're planning to release next version in few weeks.
There are some important changes, including new widgets, such as CDataForm and others.

We also planning to release new script, called Restaurant Site (currently in final stage) that will be written fully on our new framework.

To get you some ideas please look below:

Login Controller:

Code: Select all

if($cRequest->getPost('act') == 'send'){         
    // perform login form validation
    $result = CWidget::create('CFormValidation', array(
        'fields'=>array(
            'username'=>array('title'=>A::t('app', 'Username'), 'validation'=>array('required'=>true, 'type'=>'username', 'minLength'=>6, 'maxLength'=>20)),
            'password'=>array('title'=>A::t('app', 'Password'), 'validation'=>array('required'=>true, 'type'=>'password', 'minLength'=>6, 'maxLength'=>20)),
            'remember'=>array('title'=>A::t('app', 'Remember me'), 'validation'=>array('required'=>false, 'type'=>'set', 'source'=>array(0,1))),
        ),           
    ));
    if($result['error']){
        $msg = $result['errorMessage'];
        $this->view->errorField = $result['errorField'];
        $messageType = 'validation';               
    }else{
        if($model->login($this->view->username, $this->view->password)){
            if($this->view->remember){
                $passwordHash = CHash::encrypt($this->view->password, CConfig::get('password.hashKey'));
                A::app()->getCookie()->set('auth', 'usr='.$this->view->username.'&hash='.$passwordHash, time() + 3600 * 24 * 14);
            }
            $this->redirect('backend/index');   
        }else{
            $msg = A::t('app', 'Login Error Message');
            $this->view->errorField = 'username';
            $messageType = 'error';
        }
    }

    if(!empty($msg)){            
        $this->view->username = $cRequest->getPost('username', 'string');
        $this->view->password = $cRequest->getPost('password', 'string');
        $this->view->remember = $cRequest->getPost('remember', 'string');
       
        $this->view->actionMessage = CWidget::create('CMessage', array($messageType, $msg));
    }         
}else{
    $this->view->actionMessage = CWidget::create('CMessage', array('info', $msg));
}


Login model:

Code: Select all

$result = $this->db->select('
    SELECT *
    FROM '.CConfig::get('db.prefix').$this->_table.'
    WHERE username = :username AND password = :password AND is_active = 1',
    array(
        ':username' => $username,
        ':password' => ((CConfig::get('password.encryption')) ? CHash::create(CConfig::get('password.encryptAlgorithm'), $password, CConfig::get('password.hashKey')) : $password)
    )
);

if(!empty($result)){
    $session = A::app()->getSession();
    $session->set('loggedIn', true);
    $session->set('loggedId', $result[0]['id']);
    $session->set('loggedRole', $result[0]['role']);

    // set current language
    A::app()->setLanguage($result[0]['language_code']);

    // update admin's last visit time
    $this->db->update($this->_table, array('lastvisited_at' => date('Y-m-d H:i:s')), 'id = '.(int)CAuth::getLoggedId());
    return true;
}else{
   
    return false;       
}       

Jonathan
Newbie
Newbie
Posts: 7
Joined: Jul 16th, '13, 08:56

Re: User management

Postby Jonathan » Jul 17th, '13, 09:16

tnx for example! ill be waiting

paragate
Master
Master
Posts: 151
Joined: Nov 13th, '14, 13:04
Location: Denmark, Odense

Re: User management

Postby paragate » Aug 19th, '16, 11:16

another solution could be to buy the users module..


Return to “ApPHP MVC Framework {developers/users}”