コード例 #1
0
        public async Task <HttpResponseMessage> PostAsync([FromBody] AuthorizationViewModel authVM)
        {
            // check if the logIn user exists
            var error = await ValidationService.ValidateLogInUser(authVM.UserName, authVM.Password);

            if (error != null)
            {
                ModelState.AddModelError("Username", error.description);
            }
            if (!ModelState.IsValid)
            {
                // if there is no user with authVM parameters return empty result
                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            // logging in
            UserLogInDTO     userLogInDTO = AMapper.Mapper.Map <AuthorizationViewModel, UserLogInDTO>(authVM);
            UserGetDetailDTO userGetDTO   = await UserService.LogIn(userLogInDTO);

            // set auth and userCookie
            FormsAuthentication.SetAuthCookie(userGetDTO.UserName, true);
            var response = Request.CreateResponse <int>(HttpStatusCode.OK, userGetDTO.UserID);
            var cookie   = UserCookieHelper.CreateUserCookie(userGetDTO);

            response.Headers.AddCookies(new CookieHeaderValue[] { cookie });

            return(response);
        }
コード例 #2
0
        public async Task <ErrorModel> IsAccountExists(string username, string password)
        {
            UserGetDetailDTO userGetDetailDTO = await UserService.GetUserByUserName(username);

            // if user with the userName not exists or
            // if user with the userName exists but password isn't right
            if (userGetDetailDTO == null || !IsRightPassword(password, userGetDetailDTO.HashedPassword, userGetDetailDTO.DynamicSalt))
            {
                return(ErrorHelper.AccountNotFound);
            }
            return(null);
        }
コード例 #3
0
        // create userCookie for UserGetDetailDTO
        public static CookieHeaderValue CreateUserCookie(UserGetDetailDTO user)
        {
            var httpCookie = CreateCookie(user.UserID, user.Type);

            return(httpCookie);
        }