예제 #1
0
파일: auth.php 프로젝트: cruide/wasp
 public function signin($id, $password, $type = UserContact::TYPE_EMAIL)
 {
     if (!is_scalar($id)) {
         return false;
     }
     $auth = UserContact::where('type', '=', $type)->where('value', '=', $id)->first();
     if (empty($auth)) {
         return false;
     }
     $obj = User::where('id', '=', $auth->user_id)->where('password', '=', password_crypt($password))->with('session')->first();
     if (!empty($obj->id)) {
         $session = $obj->session;
         if (empty($session->id)) {
             $session = new UserSession();
         }
         $session->session_id = $this->session->id(true);
         $session->user_id = $obj->id;
         $session->ip_address = get_ip_address();
         $session->stamp = time();
         $session->save();
         $this->autorization = true;
         $this->user = $session->user;
         $smarty = new \Smarty();
         $smarty->assignGlobal('auth_user', $this->user);
         $smarty->assignGlobal('auth', $this);
         return true;
     }
     return false;
 }