Exemplo n.º 1
0
 public function login($get, $post)
 {
     $access = Auth::instance();
     $use_captcha = Config::get('app/login/use_captcha');
     if ($access->isLogin()) {
         Router::jumpTo('user');
     }
     if ($post) {
         if ($use_captcha) {
             if (empty($post['captcha'])) {
                 return new Result('请输入验证码', false, 'captcha');
             }
             if (strtolower($post['captcha']) != strtolower(Auth::getCaptcha())) {
                 Auth::setCaptcha('');
                 return new Result('您输入的验证码不正确,请重新输入', false, 'captcha');
             }
             Auth::setCaptcha('');
         }
         if (!User::find('name=?', $post['name'])->count()) {
             return new Result('当前用户名未登记');
         }
         $user_info = User::validatePsw($post['name'], $post['password']);
         if ($user_info) {
             if ($post['auto_login']) {
                 $access->setCookieExpired(Config::get('app/login/expired'));
             } else {
                 $access->setCookieExpired(0);
             }
             Auth::instance()->login($user_info);
             return new Result('登录成功', true, null, Router::getUrl());
         }
         return new Result('用户名或密码错误');
     }
     return array('use_captcha' => $use_captcha);
 }
Exemplo n.º 2
0
 public function __construct($data = array())
 {
     $this->setPropertiesDefine(array('user' => array('getter' => function ($item) {
         return User::findOneByPk($item->user_id);
     }), 'action' => array('getter' => function ($item) {
         $all = AccessAction::find()->all(true);
         $all = array_group($all, 'id', true);
         return new AccessAction($all[$item->action_id]);
     }), 'type_text' => array('getter' => function ($item) {
         return self::$type_list[$item->type];
     })));
     parent::__construct($data);
 }
Exemplo n.º 3
0
 public function updatePassword($get, $post)
 {
     $id = $get['id'];
     $user = User::findOneByPk($id);
     if ($post) {
         if (!$post['password']) {
             return new Result('请输入密码');
         }
         if ($post['password'] != $post['repeat_password']) {
             return new Result('两次输入的密码不一致,请重新输入');
         }
         $user->password = md5($post['password']);
         $user->save();
         return new Result('密码修改成功', true);
     }
     return array('data' => $user);
 }
Exemplo n.º 4
0
 /**
  * 从用户ID中获取用户信息
  * @param $user_id
  * @return array | null
  */
 public function getUserInfoFromId($user_id)
 {
     return User::findOneByPk($user_id, true);
 }
Exemplo n.º 5
0
 /**
  * 校验用户名密码
  * @param $name
  * @param $password
  * @return array
  */
 public static function validatePsw($name, $password)
 {
     return User::find('name=? AND password=?', $name, md5($password))->one(true);
 }