|
16 | 16 | use Illuminate\Support\Facades\Auth; |
17 | 17 | use Illuminate\Support\Facades\Cookie; |
18 | 18 | use Illuminate\Validation\Rule; |
| 19 | +use Nexus\Database\NexusDB; |
19 | 20 |
|
20 | 21 | class AuthenticateController extends Controller |
21 | 22 | { |
@@ -53,17 +54,18 @@ public function passkeyLogin($passkey) |
53 | 54 | { |
54 | 55 | $deadline = Setting::get('security.login_secret_deadline'); |
55 | 56 | if ($deadline && $deadline > now()->toDateTimeString()) { |
56 | | - $user = User::query()->where('passkey', $passkey)->first(['id', 'passhash']); |
| 57 | + $user = User::query()->where('passkey', $passkey)->first(['id', 'passhash', 'secret', 'auth_key']); |
57 | 58 | if ($user) { |
58 | 59 | $ip = getip(); |
59 | 60 | /** |
60 | 61 | * Not IP related |
61 | 62 | * @since 1.8.0 |
62 | 63 | */ |
63 | 64 | // $passhash = md5($user->passhash . $ip); |
64 | | - $passhash = md5($user->passhash); |
65 | | - do_log(sprintf('passhash: %s, ip: %s, md5: %s', $user->passhash, $ip, $passhash)); |
66 | | - logincookie($user->id, $passhash,false, get_setting('system.cookie_valid_days', 365) * 86400, true, true, true); |
| 65 | +// $passhash = md5($user->passhash); |
| 66 | +// do_log(sprintf('passhash: %s, ip: %s, md5: %s', $user->passhash, $ip, $passhash)); |
| 67 | +// logincookie($user->id, $passhash,false, get_setting('system.cookie_valid_days', 365) * 86400, true, true, true); |
| 68 | + logincookie($user->id, $user->auth_key); |
67 | 69 | $user->last_login = now(); |
68 | 70 | $user->save(); |
69 | 71 | $userRep = new UserRepository(); |
@@ -126,6 +128,29 @@ public function ammdsApprove(Request $request) |
126 | 128 | } |
127 | 129 | } |
128 | 130 |
|
| 131 | + public function challenge(Request $request) |
| 132 | + { |
| 133 | + try { |
| 134 | + $request->validate([ |
| 135 | + 'username' => 'required|string', |
| 136 | + ]); |
| 137 | + $username = $request->username; |
| 138 | + $challenge = mksecret(); |
| 139 | + NexusDB::cache_put(get_challenge_key($username), $challenge,300); |
| 140 | + $user = User::query()->where("username", $username)->first(['secret']); |
| 141 | + return $this->success([ |
| 142 | + "challenge" => $challenge, |
| 143 | + 'secret' => $user->secret ?? mksecret(), |
| 144 | + ]); |
| 145 | + } catch (\Exception $exception) { |
| 146 | + $msg = $exception->getMessage(); |
| 147 | + $params = $request->all(); |
| 148 | + do_log(sprintf("challenge fail: %s, params: %s", $msg, nexus_json_encode($params))); |
| 149 | + return $this->fail($params, $msg); |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + |
129 | 154 |
|
130 | 155 |
|
131 | 156 |
|
|
0 commit comments