Skip to content

Commit

Permalink
Merge pull request #10 from MycroftAI/dev
Browse files Browse the repository at this point in the history
2018.3 to master
  • Loading branch information
chrisveilleux authored Oct 30, 2018
2 parents 42d1d18 + 02c36b4 commit 29969cf
Show file tree
Hide file tree
Showing 90 changed files with 2,211 additions and 1,287 deletions.
4 changes: 2 additions & 2 deletions login/backend/v1/login-api/login_api/endpoints/logout.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LogoutEndpoint(SeleneEndpoint):
def __init__(self):
super(LogoutEndpoint, self).__init__()

def put(self):
def get(self):
try:
self._authenticate()
self._logout()
Expand All @@ -33,5 +33,5 @@ def _logout(self):
headers=service_request_headers
)
self._check_for_service_errors(auth_service_response)
logout_response = auth_service_response.json()
logout_response = auth_service_response.content.decode()
self.response = (logout_response, HTTPStatus.OK)
19 changes: 19 additions & 0 deletions login/frontend/v1/login-ui/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { LoginComponent } from "./login/login.component";
import { LogoutComponent } from "./logout/logout.component";
// import { PageNotFoundComponent } from "./page-not-found/page-not-found.component";

const routes: Routes = [
{ path: 'login', component: LoginComponent },
{ path: 'logout', component: LogoutComponent },
// { path: '**', component: PageNotFoundComponent }
];

@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})
export class AppRoutingModule {
}
22 changes: 2 additions & 20 deletions login/frontend/v1/login-ui/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,6 @@
is refactored and moved into Selene.
-->
<div *ngIf="!socialLoginDataFound">
<div class="split top"></div>
<div class="split bottom"></div>
<div fxLayout="column" fxLayoutAlign="center center">
<div align="center">
<img src="../../assets/mycroft-ai-no-logo.svg"/>
</div>
<div class="login-options">
<login-authenticate></login-authenticate>
<!--<mat-tab-group>-->
<!--<mat-tab label="LOG IN">-->
<!--<login-authenticate></login-authenticate>-->
<!--</mat-tab>-->
<!--<mat-tab label="SIGN UP">-->
<!--<login-auth-social></login-auth-social>-->
<!--<div class="mat-subheading-2">OR</div>-->
<!--<login-auth-antisocial></login-auth-antisocial>-->
<!--</mat-tab>-->
<!--</mat-tab-group>-->
</div>
</div>
<login-background></login-background>
<router-outlet></router-outlet>
</div>
27 changes: 0 additions & 27 deletions login/frontend/v1/login-ui/src/app/app.component.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion login/frontend/v1/login-ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class AppComponent implements OnInit {
ngOnInit () {
let uriParams = decodeURIComponent(window.location.search);

if (uriParams) {
if (!window.location.pathname && uriParams) {
this.socialLoginDataFound = true;
window.opener.postMessage(uriParams, window.location.origin);
window.close();
Expand Down
12 changes: 9 additions & 3 deletions login/frontend/v1/login-ui/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ import { FlexLayoutModule } from "@angular/flex-layout";
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { AuthModule } from "./auth/auth.module";
import { AppRoutingModule } from "./app-routing.module";
import { BackgroundModule } from "./background/background.module";
import { LoginModule } from "./login/login.module";
import { LogoutModule } from "./logout/logout.module";

@NgModule({
declarations: [ AppComponent ],
imports: [
BrowserModule,
AuthModule,
BackgroundModule,
BrowserAnimationsModule,
FlexLayoutModule
FlexLayoutModule,
LoginModule,
LogoutModule,
AppRoutingModule
],
providers: [ ],
bootstrap: [ AppComponent ]
Expand Down
91 changes: 91 additions & 0 deletions login/frontend/v1/login-ui/src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders} from "@angular/common/http";

import { Observable } from 'rxjs';

export interface AuthResponse {
expiration: number;
seleneToken: string;
tartarusToken: string;
}

export interface SocialLoginData {
uuid: string;
accessToken: string;
refreshToken: string;
expiration: string;
}

const antisocialAuthUrl = '/api/antisocial';
const facebookAuthUrl = '/api/social/facebook';
const githubAuthUrl = '/api/social/github';
const googleAuthUrl = '/api/social/google';
const generateTokensUrl = 'api/social/tokens';
const logoutUrl = '/api/logout';


@Injectable()
export class AppService {
private cookieDomain: string = document.domain.replace('login.', '');

constructor(private http: HttpClient) { }

navigateToRedirectURI(delay: number): void {
let redirectURI = localStorage.getItem('redirect');
localStorage.removeItem('redirect');
setTimeout(() => { window.location.assign(redirectURI) }, delay);
}

authorizeAntisocial (username, password): Observable<AuthResponse> {
let rawCredentials = `${username}:${password}`;
const codedCredentials = btoa(rawCredentials);
const httpHeaders = new HttpHeaders(
{"Authorization": "Basic " + codedCredentials}
);
return this.http.get<AuthResponse>(antisocialAuthUrl, {headers: httpHeaders})
}

authenticateWithFacebook() {
window.location.assign(facebookAuthUrl);
}

authenticateWithGithub() {
window.location.assign(githubAuthUrl);
}

authenticateWithGoogle() {
window.location.assign(googleAuthUrl);
}

generateSocialLoginTokens(socialLoginData: any) {
return this.http.post<AuthResponse>(
generateTokensUrl,
socialLoginData
);
}

generateTokenCookies(authResponse: AuthResponse) {
let expirationDate = new Date(authResponse.expiration * 1000);
document.cookie = 'seleneToken=' + authResponse.seleneToken +
'; expires=' + expirationDate.toUTCString() +
'; domain=' + this.cookieDomain;
document.cookie = 'tartarusToken=' + authResponse.tartarusToken +
'; expires=' + expirationDate.toUTCString() +
'; domain=' + this.cookieDomain;
}

logout(): Observable<any> {
return this.http.get(logoutUrl);
}

expireTokenCookies(): void {
let expiration = new Date();
document.cookie = 'seleneToken=""' +
'; expires=' + expiration.toUTCString() +
'; domain=' + this.cookieDomain;
document.cookie = 'tartarusToken=""' +
'; expires=' + expiration.toUTCString() +
'; domain=' + this.cookieDomain;

}
}
75 changes: 0 additions & 75 deletions login/frontend/v1/login-ui/src/app/auth/auth.component.scss

This file was deleted.

25 changes: 0 additions & 25 deletions login/frontend/v1/login-ui/src/app/auth/auth.component.spec.ts

This file was deleted.

55 changes: 0 additions & 55 deletions login/frontend/v1/login-ui/src/app/auth/auth.component.ts

This file was deleted.

13 changes: 0 additions & 13 deletions login/frontend/v1/login-ui/src/app/auth/auth.module.spec.ts

This file was deleted.

Loading

0 comments on commit 29969cf

Please sign in to comment.