quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
 
namespace app\operations\controller;
 
use app\operations\model\plus\operations\User;
use think\facade\Session;
 
/**
 * 区域代理认证
 */
class Passport extends Controller
{
    /**
     * 区域代理后台登录
     */
    public function login()
    {
        //登录前清空session
        session('jjjshop_operations', null);
        $userData = $this->postData();
        $username = $userData['username'];
        $password = $userData['password'];
        
        // 使用正确的区域代理登录模型验证登录
        $user = User::login($username, $password);
        if ($user) {
            // 保存登录状态
            $this->loginState($user);
            return $this->renderSuccess('登录成功', $username);
        }
        return $this->renderError('登录失败,用户名或密码错误');
    }
 
    /**
     * 保存登录状态
     */
    private function loginState($user)
    {
        // 保存登录状态到session
        $session = [
            'user' => [
                'operations_user_id' => $user['operations_user_id'],
                'user_id' => $user['user_id'],
                'user_name' => $user['user_name'],
                'real_name' => $user['real_name'],
                'is_super' => $user['is_super'],
            ],
            'app' => [
                'app_id' => $user['app_id'],
            ],
            'is_login' => true,
        ];
        Session::set('jjjshop_operations', $session);
    }
 
    /**
     * 退出登录
     */
    public function logout()
    {
        session('jjjshop_operations', null);
        return $this->renderSuccess('退出成功');
    }
 
    /*
   * 修改密码
   */
    public function editPass()
    {
        $postData = $this->postData();
        $user = $this->store['user'];
        
        // 获取当前用户信息
        $userLogin = User::detail($user['operations_user_id']);
        if (!$userLogin) {
            return $this->renderError('用户不存在');
        }
 
        // 验证新密码一致性
        if ($postData['password'] != $postData['confirmPass']) {
            return $this->renderError('两次输入的密码不一致');
        }
        // 验证旧密码
        if (salt_hash($postData['oldpass'])!= $userLogin['password']) {
            return $this->renderError('旧密码错误');
        }
 
        
        // 更新密码
        $userLogin->password = salt_hash($postData['password']);
        $userLogin->update_time = time();
        
        if ($userLogin->save()) {
            return $this->renderSuccess('修改成功');
        }
        return $this->renderError('修改失败');
    }
 
    /**
     * 区域代理后台登录
     */
    public function saasLogin()
    {
        //登录前清空session
        $store = session('jjjshop_operations');
        if($store != null){
            return $this->renderSuccess('登录成功', $store['user']['user_name']);
        }
        return $this->renderError('自动登录失败,请手动输入');
    }
}