Пример #1
0
 public static function do_login_action()
 {
     // 拦截
     self::method('post');
     try {
         // 校验
         $checker = new lazy_checker(p());
         $checker->check('name', array('change_to' => 'string', 'cannot_be' => array('', '用户不能为空')));
         $checker->check('pass', array('change_to' => 'string', 'cannot_be' => array('', '密码不能为空')));
         // 执行
         $member = member_model::get_one(array('name' => $checker->name));
         if ($member === null) {
             $checker->failed('name', '用户名不正确');
         }
         if (!$member->is_valid_pass($checker->pass)) {
             $checker->failed('pass', '密码不正确');
         }
         visitor::set_role('member', $member->id, p_has('remember') ? 30 * 86400 : 0, []);
         // 成功
         self::json_result(true, '登录成功', 0, url('site/admin'));
     } catch (check_failed $e) {
         // 失败
         self::json_result(false, $e->get_reasons());
     }
 }
Пример #2
0
 public static function do_setting_action()
 {
     self::method('post');
     self::role('user');
     self::csrf('user');
     try {
         $checker = new lazy_checker(p());
         $checker->check('pass', array('change_to' => 'string', 'pass_if_be' => '', 'char_size' => array(6, -1, '')));
         $checker->check('new_pass', array('change_to' => 'string', 'pass_if_be' => '', 'char_size' => array(6, -1, '')));
         if (p_has('avatar')) {
             $checker->check('avatar', array('change_to' => 'array'));
         }
         $pass = $checker->pass;
         if ($pass !== '') {
             $user_id = visitor::get_role_id('user');
             $user = user_model::get_by_id($user_id);
             if (!$user->is_valid_pass($checker->pass)) {
                 $checker->failed('pass', '原密码不正确。');
             } else {
                 if ($checker->new_pass !== p_str('re_pass')) {
                     $checker->failed('new_pass', '两次输入的密码不相同。');
                 } else {
                     $user->change_pass_to($checker->new_pass);
                     $user->save();
                 }
             }
         }
         self::json_result(true, '', 0, url('user/setting'));
     } catch (check_failed $e) {
         self::json_result(false, $e->get_reasons());
     }
 }
Пример #3
0
 public static function do_login_action()
 {
     self::method('post');
     try {
         $checker = new lazy_checker(p());
         $checker->check('name', array('change_to' => 'string', 'cannot_be' => array('', '用户名不能为空')));
         $checker->check('pass', array('change_to' => 'string', 'cannot_be' => array('', '密码不能为空')));
         $admin = admin_model::get_one(array('name' => $checker->name));
         if ($admin === null) {
             $checker->failed('name', '用户不存在。');
         } else {
             if (!$admin->is_valid_pass($checker->pass)) {
                 $checker->failed('pass', '密码不正确');
             } else {
                 visitor::set_role('admin', $admin->id, p_has('remember') ? 30 * 86400 : 0, array('name' => $admin->name));
                 self::json_result(true, '', 0, url('admin-site/index'));
             }
         }
     } catch (check_failed $e) {
         self::json_result(false, $e->get_reasons());
     }
 }