Exemplo n.º 1
0
 public function action_sign_in()
 {
     $user = Session::get('oauth.user');
     $client = Session::get('oauth.client');
     // Check if user is signed in, if so redirect them on to /authorise
     if ($user && $client) {
         Response::redirect('oauth/authorise');
     }
     // Check there is are client parameters are stored
     if ($client === NULL) {
         $this->_fail('invalid_request', 'No client details have been saved. Have you deleted your cookies?', NULL, array(), 400);
         return;
     }
     // Errors
     $vars = array('error' => FALSE, 'error_messages' => array(), 'client_name' => $client->name);
     // If the form has been posted
     if (Input::post('validate_user')) {
         $u = trim(Input::post('username'));
         $p = trim(Input::post('password'));
         // Validate username and password
         if ($u === FALSE || empty($u)) {
             $vars['error_messages'][] = 'The username field should not be empty';
             $vars['error'] = TRUE;
         }
         if ($p === FALSE || empty($p)) {
             $vars['error_messages'][] = 'The password field should not be empty';
             $vars['error'] = TRUE;
         }
         // Check login and get credentials
         if ($vars['error'] === FALSE) {
             $user = Sentry::validate_user($u, $p, 'password');
             if ($user === FALSE) {
                 $vars['error_messages'][] = 'Invalid username and/or password';
                 $vars['error'] = TRUE;
             } else {
                 Session::set('oauth.user', (object) array('id' => $user->id, 'username' => $user->username, 'email' => $user->email, 'non_ad_user' => TRUE));
             }
         }
         // If there is no error then the user has successfully signed in
         if ($vars['error'] === FALSE) {
             Response::redirect('oauth/authorise');
         }
     }
     $this->template->body = View::forge('oauth/sign_in', $vars);
 }