-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't automatically create user on oauth signup
- Loading branch information
Showing
8 changed files
with
128 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { UserService } from '../../../services/user.service'; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
import { NwbAlertConfig, NwbAlertService } from '@wizishop/ng-wizi-bulma'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { LoadingBarService } from '../../../services/loading-bar.service'; | ||
import { AuthService } from '../../../services/auth.service'; | ||
import { firstValueFrom } from 'rxjs'; | ||
import { LoginResponse, LoginResponseStatus } from '../../../model/auth'; | ||
|
||
@Component({ | ||
selector: 'app-login-oauth', | ||
templateUrl: './login-oauth.component.html', | ||
styleUrls: ['./login-oauth.component.scss'] | ||
}) | ||
export class LoginOauthComponent implements OnInit { | ||
|
||
constructor( | ||
private authService: AuthService, | ||
private userService: UserService, | ||
private route: ActivatedRoute, | ||
private router: Router, | ||
private toastr: NwbAlertService, | ||
private translateService: TranslateService, | ||
private loader: LoadingBarService | ||
) { } | ||
|
||
ngOnInit(): void { | ||
setTimeout(() => { | ||
this.loader.setLoading(true); | ||
}, 0); | ||
|
||
this.route.params.subscribe(params => { | ||
this.route.queryParams.subscribe(queryParams => { | ||
const service = params['service']; | ||
const code = queryParams['code']; | ||
|
||
this.loginTo(service, code); | ||
}); | ||
}); | ||
} | ||
|
||
async loginTo(service: string, code: string): Promise<void> { | ||
try { | ||
const response = await firstValueFrom(this.authService.performOauthLogin({ service, code })); | ||
|
||
switch (response.status) { | ||
case LoginResponseStatus.LOGIN_SUCCESS: | ||
this.userService.token = response.token; | ||
this.userService.me().add(() => { | ||
if (this.userService.user.mail) { | ||
const item = localStorage.getItem('prev_loc') || '/'; | ||
localStorage.removeItem('prev_loc'); | ||
|
||
this.router.navigate([item]); | ||
} | ||
}); | ||
return; | ||
} | ||
} catch (e: any) { | ||
const { error }: { error: LoginResponse } = e; | ||
|
||
switch (error.status) { | ||
case LoginResponseStatus.ACCOUNT_DISABLED: | ||
this.disabledAccountToast(); | ||
return; | ||
case LoginResponseStatus.OAUTH_ACCOUNT_NOT_FOUND: | ||
this.unknownAccountToast(); | ||
return; | ||
default: | ||
this.router.navigate(['/']); | ||
this.translateService.get('alert.user.login.error').subscribe((res: string) => { | ||
const alertConfig: NwbAlertConfig = { | ||
message: res + '\n\nCode: ' + error.status, | ||
duration: 5000, | ||
position: 'is-right', | ||
color: 'is-warning' | ||
}; | ||
this.toastr.open(alertConfig); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
unknownAccountToast() { | ||
this.router.navigate(['/register']); | ||
|
||
// TODO: translation | ||
const alertConfig: NwbAlertConfig = { | ||
message: 'Account not found, please register for a new account or sync with an existing account.', | ||
duration: 8000, | ||
position: 'is-right', | ||
color: 'is-warning' | ||
}; | ||
this.toastr.open(alertConfig); | ||
} | ||
|
||
disabledAccountToast() { | ||
this.router.navigate(['/']); | ||
this.translateService.get('alert.user.login.disabledAccount').subscribe((res: string) => { | ||
const alertConfig: NwbAlertConfig = { | ||
message: res, | ||
duration: 5000, | ||
position: 'is-right', | ||
color: 'is-warning' | ||
}; | ||
this.toastr.open(alertConfig); | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Submodule i18n
updated
from f4e978 to a8696c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters