Пример #1
0
        public void CheckUser_Should_Call_Repository_To_Check_If_User_Exists()
        {
            var user = new User
            {
                UserName     = "******",
                PasswordHash = "test"
            };

            _userManager.LoadByUserName(user.UserName);

            _userRepositoryMock.Verify(x => x.LoadByUserName(user.UserName), Times.Once());
        }
Пример #2
0
        public HttpResponseMessage Login(UserViewModel user)
        {
            if (user == null || !ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            var existingUser = _userLoader.LoadByUserName(user.UserName);

            if (IsInvalidUserNameOrPassword(user, existingUser))
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            var token = EncryptionHelper.CreateToken(_userLoader.LoadByUserName(user.UserName));

            return(Request.CreateResponse(HttpStatusCode.OK,
                                          new
            {
                username = user.UserName,
                token,
                success = true
            }));
        }