Page MenuHomePhorge

D1696.1775174042.diff
No OneTemporary

Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None

D1696.1775174042.diff

diff --git a/src/app/Http/Controllers/API/AuthController.php b/src/app/Http/Controllers/API/AuthController.php
--- a/src/app/Http/Controllers/API/AuthController.php
+++ b/src/app/Http/Controllers/API/AuthController.php
@@ -38,8 +38,10 @@
{
// @phpstan-ignore-next-line
$token = Auth::guard()->login($user);
+ $response = V4\UsersController::userResponse($user);
+ $response['status'] = 'success';
- return self::respondWithToken($token, ['status' => 'success']);
+ return self::respondWithToken($token, $response);
}
/**
@@ -67,13 +69,16 @@
$credentials = $request->only('email', 'password');
if ($token = Auth::guard()->attempt($credentials)) {
- $sf = new \App\Auth\SecondFactor(Auth::guard()->user());
+ $user = Auth::guard()->user();
+ $sf = new \App\Auth\SecondFactor($user);
if ($response = $sf->requestHandler($request)) {
return $response;
}
- return $this->respondWithToken($token);
+ $response = V4\UsersController::userResponse($user);
+
+ return $this->respondWithToken($token, $response);
}
return response()->json(['status' => 'error', 'message' => __('auth.failed')], 401);
diff --git a/src/resources/js/app.js b/src/resources/js/app.js
--- a/src/resources/js/app.js
+++ b/src/resources/js/app.js
@@ -59,6 +59,10 @@
localStorage.setItem('token', response.access_token)
axios.defaults.headers.common.Authorization = 'Bearer ' + response.access_token
+ if (response.email) {
+ store.state.authInfo = response
+ }
+
if (dashboard !== false) {
this.$router.push(store.state.afterLogin || { name: 'dashboard' })
}
diff --git a/src/resources/sass/app.scss b/src/resources/sass/app.scss
--- a/src/resources/sass/app.scss
+++ b/src/resources/sass/app.scss
@@ -88,7 +88,7 @@
&.fadeOut {
visibility: hidden;
opacity: 0;
- transition: visibility 400ms linear, opacity 400ms linear;
+ transition: visibility 300ms linear, opacity 300ms linear;
}
}
diff --git a/src/resources/vue/App.vue b/src/resources/vue/App.vue
--- a/src/resources/vue/App.vue
+++ b/src/resources/vue/App.vue
@@ -19,10 +19,9 @@
axios.get('/api/auth/info?refresh_token=1')
.then(response => {
- this.isLoading = false
- this.$root.stopLoading()
this.$root.loginUser(response.data, false)
- this.$store.state.authInfo = response.data
+ this.$root.stopLoading()
+ this.isLoading = false
})
.catch(error => {
// Release lock on the router-view, otherwise links (e.g. Logout) will not work
diff --git a/src/resources/vue/Dashboard.vue b/src/resources/vue/Dashboard.vue
--- a/src/resources/vue/Dashboard.vue
+++ b/src/resources/vue/Dashboard.vue
@@ -34,22 +34,9 @@
}
},
mounted() {
- const authInfo = this.$store.state.isLoggedIn ? this.$store.state.authInfo : null
-
- if (authInfo) {
- this.status = authInfo.statusInfo
- this.getBalance(authInfo)
- } else {
- this.$root.startLoading()
- axios.get('/api/auth/info')
- .then(response => {
- this.$store.state.authInfo = response.data
- this.status = response.data.statusInfo
- this.getBalance(response.data)
- this.$root.stopLoading()
- })
- .catch(this.$root.errorHandler)
- }
+ const authInfo = this.$store.state.authInfo
+ this.status = authInfo.statusInfo
+ this.getBalance(authInfo)
},
methods: {
getBalance(authInfo) {
diff --git a/src/tests/Feature/Controller/AuthTest.php b/src/tests/Feature/Controller/AuthTest.php
--- a/src/tests/Feature/Controller/AuthTest.php
+++ b/src/tests/Feature/Controller/AuthTest.php
@@ -101,6 +101,7 @@
$this->assertSame('Invalid username or password.', $json['message']);
// Valid user+password
+ $user = $this->getTestUser('john@kolab.org');
$post = ['email' => 'john@kolab.org', 'password' => 'simple123'];
$response = $this->post("api/auth/login", $post);
$json = $response->json();
@@ -109,6 +110,11 @@
$this->assertTrue(!empty($json['access_token']));
$this->assertEquals(\config('jwt.ttl') * 60, $json['expires_in']);
$this->assertEquals('bearer', $json['token_type']);
+ $this->assertEquals($user->id, $json['id']);
+ $this->assertEquals($user->email, $json['email']);
+ $this->assertTrue(is_array($json['statusInfo']));
+ $this->assertTrue(is_array($json['settings']));
+ $this->assertTrue(is_array($json['aliases']));
// Valid user+password (upper-case)
$post = ['email' => 'John@Kolab.org', 'password' => 'simple123'];
diff --git a/src/tests/Feature/Controller/PasswordResetTest.php b/src/tests/Feature/Controller/PasswordResetTest.php
--- a/src/tests/Feature/Controller/PasswordResetTest.php
+++ b/src/tests/Feature/Controller/PasswordResetTest.php
@@ -304,11 +304,12 @@
$json = $response->json();
$response->assertStatus(200);
- $this->assertCount(4, $json);
$this->assertSame('success', $json['status']);
$this->assertSame('bearer', $json['token_type']);
$this->assertTrue(!empty($json['expires_in']) && is_int($json['expires_in']) && $json['expires_in'] > 0);
$this->assertNotEmpty($json['access_token']);
+ $this->assertSame($user->email, $json['email']);
+ $this->assertSame($user->id, $json['id']);
Queue::assertPushed(\App\Jobs\UserUpdate::class, 1);
Queue::assertPushed(\App\Jobs\UserUpdate::class, function ($job) use ($user) {
diff --git a/src/tests/Feature/Controller/SignupTest.php b/src/tests/Feature/Controller/SignupTest.php
--- a/src/tests/Feature/Controller/SignupTest.php
+++ b/src/tests/Feature/Controller/SignupTest.php
@@ -475,11 +475,11 @@
$json = $response->json();
$response->assertStatus(200);
- $this->assertCount(4, $json);
$this->assertSame('success', $json['status']);
$this->assertSame('bearer', $json['token_type']);
$this->assertTrue(!empty($json['expires_in']) && is_int($json['expires_in']) && $json['expires_in'] > 0);
$this->assertNotEmpty($json['access_token']);
+ $this->assertSame($identity, $json['email']);
Queue::assertPushed(\App\Jobs\UserCreate::class, 1);
Queue::assertPushed(\App\Jobs\UserCreate::class, function ($job) use ($data) {
@@ -586,11 +586,11 @@
$result = $response->json();
$response->assertStatus(200);
- $this->assertCount(4, $result);
$this->assertSame('success', $result['status']);
$this->assertSame('bearer', $result['token_type']);
$this->assertTrue(!empty($result['expires_in']) && is_int($result['expires_in']) && $result['expires_in'] > 0);
$this->assertNotEmpty($result['access_token']);
+ $this->assertSame("$login@$domain", $result['email']);
Queue::assertPushed(\App\Jobs\DomainCreate::class, 1);
Queue::assertPushed(\App\Jobs\DomainCreate::class, function ($job) use ($domain) {

File Metadata

Mime Type
text/plain
Expires
Thu, Apr 2, 11:54 PM (4 h, 25 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18768909
Default Alt Text
D1696.1775174042.diff (7 KB)

Event Timeline