Exemple #1
0
        public async Task <UserResponseDto> AuthenticateAsync(string username, string password)
        {
            // Check if username exists
            var user = await _repositoryWraper.Users
                       .FindByCondition(x => x.Email == username)
                       .Include(i => i.RoleMaster).FirstOrDefaultAsync();

            if (user == null)
            {
                return(null);
            }

            // verify password
            bool isValitPassword = _passwordService.VerifyPassword(password, user.PasswordHash, user.PasswordSalt);

            if (!isValitPassword)
            {
                return(null);
            }

            var userModel = _mapper.Map <UserResponseDto>(user);

            userModel.RoleCode = user.RoleMaster.RoleCode;

            userModel.Token = AuthenticationConfig.GenerateJSONWebToken(_configuration, userModel);
            return(userModel);
        }
Exemple #2
0
        public IActionResult ChangeRole(Passcode passcode)
        {
            try
            {
                WriteLog(LogsDef.StartLogMsg);

                var passcodeDt = passcodeRepository.ReadByIdAndCode(passcode);

                if (passcodeDt != null)
                {
                    var token = AuthenticationConfig.GenerateJSONWebToken(passcodeDt);

                    var useState = new UseState();
                    useState.Date   = DateTime.UtcNow;
                    useState.IdRole = passcodeDt.IdRole;
                    useState.Token  = token;
                    useStateRepository.Add(useState);

                    HttpContext.Session.SetObjectAsJson(SessionDef.SESSION_USESTATE, useState);
                    HttpContext.Session.SetObjectAsJson(SessionDef.SESSION_USERLOGIN, passcodeDt);
                    return(Json(true));
                }

                return(Json(false));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public string Get(string user, string pass)
 {
     //return new string[] { "value1", "value2" };
     if (user == "admin")
     {
         return(AuthenticationConfig.GenerateJSONWebToken(user));
     }
     else
     {
         return(string.Empty);
     }
 }