From 79747339a0ec815b6739408ba9c2ca323faeca8a Mon Sep 17 00:00:00 2001 From: Ryan Chenkie Date: Mon, 23 Jan 2017 14:53:26 -0500 Subject: [PATCH] Update README.md --- 02-Custom-Login/README.md | 175 -------------------------------------- 1 file changed, 175 deletions(-) diff --git a/02-Custom-Login/README.md b/02-Custom-Login/README.md index 531e18f..726dab0 100644 --- a/02-Custom-Login/README.md +++ b/02-Custom-Login/README.md @@ -22,178 +22,3 @@ npm install -g serve # Run serve ``` - - -## Important Snippets - -### 1. Add `auth0.js` and `angular-auth.js` dependencies - -```html - - - ... - - - - - ... - -``` - -### 2. Login with auth0 - -```js -// components/auth/auth.service.js -(function () { - - ... - - function authService(angularAuth0, authManager, $location) { - - function login(username, password, callback) { - angularAuth0.login({ - connection: 'Username-Password-Authentication', - responseType: 'token', - email: username, - password: password, - }, callback); - } - - function signup(username, password, callback) { - angularAuth0.signup({ - connection: 'Username-Password-Authentication', - responseType: 'token', - email: username, - password: password - }, callback); - } - - function googleLogin(callback) { - angularAuth0.login({ - connection: 'google-oauth2', - responseType: 'token' - }, callback); - } - - - // Logging out just requires removing the user's - // id_token and profile - function logout() { - localStorage.removeItem('id_token'); - localStorage.removeItem('profile'); - authManager.unauthenticate(); - } - - function authenticateAndGetProfile() { - var result = angularAuth0.parseHash(window.location.hash); - - if (result && result.idToken) { - localStorage.setItem('id_token', result.idToken); - authManager.authenticate(); - angularAuth0.getProfile(result.idToken, function (error, profileData) { - if (error) { - console.log(error); - } - - localStorage.setItem('profile', JSON.stringify(profileData)); - $location.path('/'); - }); - } else if (result && result.error) { - alert('error: ' + result.error); - } - } - - return { - login: login, - logout: logout, - authenticateAndGetProfile: authenticateAndGetProfile, - signup: signup, - googleLogin: googleLogin - } - } -})(); -``` - -### 3. Display `username` and `password` inputs, `login` and `loginWithGoogle` buttons - -```html - -
-

-

Login

-

{{message}}

-
-
-
-
-
-
- - -
- - -
- - -
-
- Login with Google
-
-
-
-``` - -### 4. Update the `Login` controller - -```js -// components/login/login.controller.js -(function () { - - ... - - function loginController($scope, authService) { - - // Put the authService on $scope to access - // the login method in the view - $scope.authService = authService; - - $scope.login = function () { - // Show loading indicator - $scope.message = 'loading...'; - $scope.loading = true; - authService.login($scope.user, $scope.pass, function (err) { - if (err) { - $scope.message = "something went wrong: " + err.message; - $scope.loading = false; - } - }); - }; - - $scope.signup = function () { - // Show loading indicator - $scope.message = 'loading...'; - $scope.loading = true; - authService.signup($scope.user, $scope.pass, function (err) { - if (err) { - $scope.message = "something went wrong: " + err.message; - $scope.loading = false; - } - }); - }; - - $scope.googleLogin = function () { - $scope.message = 'loading...'; - $scope.loading = true; - - authService.googleLogin(function (err) { - if (err) { - $scope.message = "something went wrong: " + err.message; - $scope.loading = false; - } - }); - }; - } - -})(); -``` \ No newline at end of file