PUNKT-15 Update Logowanie przez USOS
This commit is contained in:
parent
953b8f0dab
commit
f3be31ed7e
@ -6,6 +6,7 @@ import 'rxjs/add/operator/catch';
|
||||
import 'rxjs/add/observable/throw';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { Subject } from 'rxjs/Subject';
|
||||
import { USOSUrl, LoginKey } from './login';
|
||||
|
||||
@Injectable()
|
||||
export class AuthenticationService {
|
||||
@ -66,8 +67,8 @@ export class AuthenticationService {
|
||||
}
|
||||
}
|
||||
|
||||
getUSOSTokens(): Observable<string> {
|
||||
return this.http.get<string>(encodeURI('usos/request_token?oauth_callback=http://localhost:4200/login/usos'));
|
||||
getUSOSTokens(): Observable<USOSUrl> {
|
||||
return this.http.get<USOSUrl>(encodeURI('usos/request_token?oauth_callback=http://localhost:4200/login/usos'));
|
||||
}
|
||||
|
||||
getToken(): String {
|
||||
@ -79,14 +80,14 @@ export class AuthenticationService {
|
||||
}
|
||||
}
|
||||
|
||||
getAccessByUSOS(outh_t: string, outh_t_secret: string, outh_ver: string): Observable<string> {
|
||||
getAccessByUSOS(outh_t: string, outh_t_secret: string, outh_ver: string): Observable<LoginKey> {
|
||||
const headers = new HttpHeaders({
|
||||
'oauth_token' : outh_t,
|
||||
'oauth_token_secret': outh_t_secret,
|
||||
'oauth_verifier' : outh_ver
|
||||
});
|
||||
|
||||
return this.http.get<string>('usos/access_token' , {headers: headers});
|
||||
return this.http.get<LoginKey>('usos/access_token' , {headers: headers});
|
||||
}
|
||||
|
||||
isLoggedIn(): boolean {
|
||||
|
14
FrontEnd/src/app/login.ts
Normal file
14
FrontEnd/src/app/login.ts
Normal file
@ -0,0 +1,14 @@
|
||||
export class USOSUrl {
|
||||
|
||||
url: string;
|
||||
|
||||
constructor() {}
|
||||
}
|
||||
|
||||
export class LoginKey {
|
||||
|
||||
key: string;
|
||||
username: string;
|
||||
|
||||
constructor() {}
|
||||
}
|
@ -9,10 +9,7 @@ import { Router, ActivatedRoute } from '@angular/router';
|
||||
})
|
||||
export class LoginUsosComponent implements OnInit {
|
||||
|
||||
username = '';
|
||||
|
||||
constructor(private authenticationService: AuthenticationService,
|
||||
private activatedRoute: ActivatedRoute,
|
||||
private router: Router) {}
|
||||
|
||||
|
||||
@ -23,7 +20,7 @@ export class LoginUsosComponent implements OnInit {
|
||||
this.authenticationService.getAccessByUSOS(localStorage.getItem('outh_token'),
|
||||
localStorage.getItem('outh_token_secret'), localStorage.getItem('oauth_verifier')).subscribe(
|
||||
message => {
|
||||
this.authenticationService.usosLogin(this.username, message);
|
||||
this.authenticationService.usosLogin(message.username, message.key);
|
||||
this.router.navigate(['/home']);
|
||||
}
|
||||
);
|
||||
|
@ -56,7 +56,7 @@ export class LoginComponent implements OnInit {
|
||||
loginWithUsos() {
|
||||
let array = [] as string[];
|
||||
this.authenticationService.getUSOSTokens().subscribe(el => {
|
||||
array = el.split('?');
|
||||
array = el.url.split('?');
|
||||
array = array[1].split('&');
|
||||
this.outh_token = array[0];
|
||||
this.outh_token = this.outh_token.replace('oauth_token=', '');
|
||||
@ -64,7 +64,7 @@ export class LoginComponent implements OnInit {
|
||||
this.outh_token_secret = this.outh_token_secret.replace('oauth_token_secret=', '');
|
||||
localStorage.setItem('outh_token', array[0].replace('oauth_token=', ''));
|
||||
localStorage.setItem('outh_token_secret', array[1].replace('oauth_token_secret=', ''));
|
||||
window.location.href = el;
|
||||
window.location.href = el.url;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user