Last active
January 7, 2016 04:04
-
-
Save camkidman/cbdfa968e130b68a1dff to your computer and use it in GitHub Desktop.
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
import {bootstrap} from 'angular2/platform/browser'; | |
import {provide} from 'angular2/core'; | |
import {HTTP_PROVIDERS} from 'angular2/http'; | |
import {AuthHttp} from 'angular2-jwt'; | |
import {Config, SATELLIZER_PROVIDERS, Auth} from 'ng2-ui-auth'; | |
import {AppComponent} from './app.component'; | |
bootstrap(AppComponent, [ | |
HTTP_PROVIDERS, | |
SATELLIZER_PROVIDERS({providers: {google: {clientId: GOOGLE_CLIENT_ID}}}), | |
provide(AuthHttp, { | |
useFactory: (auth: Auth, config: Config) => { | |
return new AuthHttp({ | |
tokenName: config.tokenName, | |
tokenGetter: () => auth.getToken(), | |
}); | |
}, | |
deps: [Auth, Config], | |
}), | |
]); |
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
import {Component, AfterContentInit, ElementRef, Renderer} from 'angular2/core'; | |
import {Router, ROUTER_DIRECTIVES} from 'angular2/router'; | |
import {FormBuilder, ControlGroup, Validators} from 'angular2/common'; | |
import {Auth} from 'ng2-ui-auth'; | |
//import {NgMessages} from '../formComponents/ngMessages'; | |
//import {CustomValidators} from '../formComponents/customValidators'; | |
//import {DefaultHandlers} from '../httpDefaults'; | |
/** | |
* Created by Ron on 18/12/2015. | |
*/ | |
@Component({ | |
selector: 'app-login', | |
// templateUrl: '../templates/login_form.html', | |
directives: [NgMessages, ROUTER_DIRECTIVES], | |
}) | |
export class Login implements AfterContentInit { | |
form: ControlGroup; | |
user = { email: '', password: '' }; | |
userControlsConfig = { | |
email: ['', Validators.compose([Validators.required, CustomValidators.email])], | |
password: ['', Validators.required], | |
}; | |
login() { | |
this.auth.login(this.user) | |
.subscribe( | |
() => this.goToMain(), | |
this.handlers.error | |
); | |
} | |
authenticate(provider: string) { | |
this.auth.authenticate(provider) | |
.subscribe( | |
() => this.goToMain(), | |
this.handlers.error | |
); | |
} | |
goToMain() { | |
this.router.navigate(['Main']); | |
} | |
ngAfterContentInit() { | |
this.renderer.setElementClass(this.element, 'app', true); | |
if (this.auth.isAuthenticated()) { | |
this.goToMain(); | |
} | |
} | |
constructor(private auth: Auth, | |
private fb: FormBuilder, | |
private router: Router, | |
private element: ElementRef, | |
private renderer: Renderer, | |
private handlers: DefaultHandlers) { | |
this.form = fb.group(this.userControlsConfig); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment