public string NewToken()
        {
            string UUID = Request.Headers["UUID"];
            ISessionTokenService sessionTokenService = servicesFactory.CreateSessionTokenService();

            return(sessionTokenService.GenerateToken(UUID, new UserAppModel {
                active = true
            }, true));
        }
        public UserAppModel GetUserByToken(Dictionary <string, string> form)
        {
            string UUID = Request.Headers["UUID"];
            ISessionTokenService sessionTokenService = servicesFactory.CreateSessionTokenService();
            string uuid = HttpContext.Request.Headers["UUID"];

            if (form != null && form["token"] != null)
            {
                return(sessionTokenService.DecryptToken(uuid, form["token"]));
            }

            throw new Exception("Token Field is Required!");
        }
Exemplo n.º 3
0
        public string Login(UserLogin command)
        {
            IUserCommandsService userCommandsService = servicesFactory.CreateUserCommandsService();
            int userId = userCommandsService.Login(command);

            if (userId > 0)
            {
                string UUID = Request.Headers["UUID"];
                ISessionTokenService sessionTokenService = servicesFactory.CreateSessionTokenService();
                return(sessionTokenService.GenerateToken(UUID, new UserAppModel {
                    id = userId, username = command.UserName, active = true
                }, true));
            }

            return("");
        }
Exemplo n.º 4
0
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            if (!string.IsNullOrEmpty(context.HttpContext.Request.Headers["UUID"]) && !string.IsNullOrEmpty(context.HttpContext.Request.Headers["Token"]))
            {
                string uuid        = context.HttpContext.Request.Headers["UUID"];
                string tokenString = context.HttpContext.Request.Headers["Token"];
                ISessionTokenService sessionTokenService = servicesFactory.CreateSessionTokenService();
                UserAppModel         user = sessionTokenService.DecryptToken(uuid, tokenString);

                if (user != null && user.id > 0)
                {
                    return;
                }
            }

            context.Result = new UnauthorizedResult();
            return;
        }
        public void CreateSessionTokenService_Test()
        {
            Assert.Inconclusive();

            #region === ARRANGE ===

            ApplicationServicesFactory servicesFactory = new ApplicationServicesFactory();

            #endregion

            #region === ACT ===

            ISessionTokenService sessionTokenService = servicesFactory.CreateSessionTokenService();

            #endregion

            #region === ASSERT ===

            Assert.IsInstanceOfType(sessionTokenService, typeof(ISessionTokenService));

            #endregion
        }
Exemplo n.º 6
0
 public ClientController(IClientService clientService, ISessionTokenService sessionTokenService, IApplicationUserService userService)
 {
     _clientService       = clientService;
     _sessionTokenService = sessionTokenService;
     _userService         = userService;
 }
Exemplo n.º 7
0
 public Authenticator(ISessionTokenService sessionTokenService, IUserService userService)
 {
     _sessionTokenService = sessionTokenService;
     _userService         = userService;
 }
Exemplo n.º 8
0
 public UserController(IApplicationUserService userSerivce, ISessionTokenService tokenService)
 {
     _userService  = userSerivce;
     _tokenService = tokenService;
 }