This file contains hidden or 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 is method does the checking for us, according to the below process | |
| * 1. check if the user is authenticated, if so check if is time to refresh token the return the observable | |
| * so our guard can resolve it, since the retrieve method is already handling the response with `do` we just map this | |
| * to true default so next view can check and see if the new token is valid or not | |
| * | |
| * 2. if the above from 1 pass through without returning it means it was false all the way | |
| * so we handle it by passing a message and updating the redirectUrl so users can continue where they left of | |
| * after authentication | |
| * @param next |
This file contains hidden or 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 {Injectable} from '@angular/core'; | |
| import {CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild, Router} from '@angular/router'; | |
| import {Observable} from 'rxjs/Observable'; | |
| import {AuthService} from "../providers/auth.service"; | |
| import 'rxjs/add/operator/mapTo'; | |
| @Injectable() | |
| export class AuthGuard implements CanActivate, CanActivateChild { |
This file contains hidden or 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 {Routes} from "@angular/router"; | |
| import {DashboardComponent} from "./dashboard/dashboard.component"; | |
| import {HomeComponent} from "./home/home.component"; | |
| import {SettingsComponent} from "./settings/settings.component"; | |
| import {AdminComponent} from "./admin/admin.component"; | |
| import {AuthGuard} from "../guards/auth.guard"; | |
| /** | |
| * Created by theophy on 04/06/2017. | |
| */ | |
| export const dashboardRoutes: Routes = [ |
This file contains hidden or 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 {Injectable} from '@angular/core'; | |
| import {CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router'; | |
| import {Observable} from 'rxjs/Observable'; | |
| import {UserService} from "../providers/user.service"; | |
| @Injectable() | |
| export class RoleGuard implements CanActivate { | |
| constructor(private _userService: UserService) { | |
| } |
This file contains hidden or 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, OnInit} from '@angular/core'; | |
| import {UserService} from "./providers/user.service"; | |
| import {JwtHelper} from "./helpers/jwt-helper"; | |
| @Component({ | |
| selector: 'app-root', | |
| templateUrl: './app.component.html', | |
| styleUrls: ['./app.component.css'] | |
| }) | |
| export class AppComponent implements OnInit { |
This file contains hidden or 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 {Injectable} from '@angular/core'; | |
| import {CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router} from '@angular/router'; | |
| import {Observable} from 'rxjs/Observable'; | |
| import {UserService} from "../providers/user.service"; | |
| @Injectable() | |
| export class RoleGuard implements CanActivate { | |
| constructor(private _userService: UserService, private _router: Router) { | |
| } |
This file contains hidden or 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
| /** | |
| * User.js | |
| * | |
| * @description :: TODO: You might write a short summary of how this model works and what it represents here. | |
| * @docs :: http://sailsjs.org/documentation/concepts/models-and-orm/models | |
| */ | |
| var bcrypt = require("bcryptjs"); | |
| module.exports = { |
This file contains hidden or 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
| /** | |
| * UserController | |
| * | |
| * @description :: Server-side logic for managing users | |
| * @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers | |
| */ | |
| var jwt = require("jsonwebtoken"); | |
| var bcrypt = require("bcryptjs"); |
This file contains hidden or 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
| /** | |
| * Created by theophy on 11/06/2017. | |
| */ | |
| var jwt = require("jsonwebtoken"); | |
| module.exports = function (req, res, next) { | |
| var bearerToken; | |
| var bearerHeader = req.headers["authorization"]; | |
| if (typeof bearerHeader !== 'undefined') { | |
| var bearer = bearerHeader.split(" "); |
This file contains hidden or 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
| /** | |
| * Policy Mappings | |
| * (sails.config.policies) | |
| * | |
| * Policies are simple functions which run **before** your controllers. | |
| * You can apply one or more policies to a given controller, or protect | |
| * its actions individually. | |
| * | |
| * Any policy file (e.g. `api/policies/authenticated.js`) can be accessed | |
| * below by its filename, minus the extension, (e.g. "authenticated") |