コード例 #1
0
        public async Task <GenericResponse <TokenResponseDto> > GetToken([FromBody] TokenDto tokenDto)
        {
            UserBo user = null;
            ServiceResult <IEnumerable <UserBo> > result;

            FilterCriteria filterCriteria = new FilterCriteria();

            filterCriteria.QueryFilter       = "EmailAddress = \"" + tokenDto.EmailAddress + "\"";
            filterCriteria.IncludeProperties = "UserType,UserRole,UserRole.Role,UserRole.Role.GrandRole";
            result = await serviceManager.User_Service.FindAsync(filterCriteria);

            if (result.Success)
            {
                user = result.Data.FirstOrDefault();
            }
            else
            {
                Log(result.Error, LogLevel.Error, this.ControllerContext.RouteData.Values);
            }

            if (user == null)
            {
                return(GenericResponse <TokenResponseDto> .Error(ResultType.Error, "Not Found!", "U_GT_01", StatusCodes.Status404NotFound));
            }

            Microsoft.AspNetCore.Identity.PasswordVerificationResult verificationResult = passwordHasher.VerifyHashedPassword(user, user.Password, tokenDto.Password);
            if (verificationResult == Microsoft.AspNetCore.Identity.PasswordVerificationResult.Failed)
            {
                return(GenericResponse <TokenResponseDto> .Error(ResultType.Error, "Password verification failed!", "U_GT_02", StatusCodes.Status404NotFound));
            }

            ServiceResult <TokenResponseDto> userTokenResult = await GetTokenResponseAsync(user);

            if (!userTokenResult.Success)
            {
                return(GenericResponse <TokenResponseDto> .Error(ResultType.Error, userTokenResult.Error, "U_GT_03", StatusCodes.Status500InternalServerError));
            }

            return(GenericResponse <TokenResponseDto> .Ok((userTokenResult.Data)));
        }
コード例 #2
0
 public IActionResult LoginUser(LoginRegVM model)
 {
     if (ModelState.IsValid)
     {
         User loggeduser = dbContext.Users.FirstOrDefault(u => u.Username == model.Credentials.Username);
         if (loggeduser == null)
         {
             ModelState.AddModelError("Credentials.Username", "Username provided is not associated with a user account");
             return(View("LoginRegPage"));
         }
         PasswordHasher <Credentials> hasher = new PasswordHasher <Credentials>();
         Microsoft.AspNetCore.Identity.PasswordVerificationResult result = hasher.VerifyHashedPassword(model.Credentials, loggeduser.Password, model.Credentials.Password);
         if (result == 0)
         {
             ModelState.AddModelError("Credentials.Password", "Password provided does not match registered user account");
             return(View("LoginRegPage"));
         }
         HttpContext.Session.SetInt32("currentuser", (int)loggeduser.UserId);
         return(RedirectToAction("Welcome", "Game"));
     }
     return(View("LoginRegPage", model));
 }
コード例 #3
0
        public IActionResult Submission(LoginUser user)
        {
            if (ModelState.IsValid)
            {
                User userInDb = dbContext.Users.FirstOrDefault(u => u.Email == user.Email);

                if (userInDb == null)
                {
                    ModelState.AddModelError("Email", "Invalid Email/Password");
                    return(View("Login"));
                }
                PasswordHasher <LoginUser> hasher = new PasswordHasher <LoginUser>();
                Microsoft.AspNetCore.Identity.PasswordVerificationResult result = hasher.VerifyHashedPassword(user, userInDb.Password, user.Password);
                if (result == 0)
                {
                    ModelState.AddModelError("Password", "Password doe not match");
                    return(View("Login"));
                }
                return(RedirectToAction("success"));
            }

            return(View("Login"));
        }