private void SetCurrentUserPrincipal(User user)
 {
     var principal = new GenericPrincipal(new GenericIdentity(user.UserName, "Basic"),
         user.Roles.Select(r => r.RoleName).ToArray());
     Thread.CurrentPrincipal = principal;
     HttpContext.Current.User = principal;
 }
Esempio n. 2
0
        public bool CreateUser(User user, string password)
        {
            var hashedPassword = Crypto.HashPassword(password);
            user.HashedPassword = hashedPassword;
            _unitOfWork.UserRepository.Add(user);
            Save();

            //if nothing happens, it must be successful
            return true;
        }
Esempio n. 3
0
        public void Can_Add_A_Record_To_The_Database()
        {
            //Arrange:
            var newUser = new User() {UserName = _randomString.NextString(10), HashedPassword = _randomString.NextString(10), Email= _randomString.NextString(20)};

            //Act:
            _userRepo.Add(newUser);
            _unitOfWork.Commit();

            //Assert:
            newUser.Id.Should(Be.GreaterThanOrEqualTo(1));
        }
Esempio n. 4
0
 public string CreateLoginToken(User user)
 {
     string token = _tokenCreator.CreateToken();
     user.AccessToken = token;
     return token;
 }
Esempio n. 5
0
 public void UpdateUser(User user)
 {
     _unitOfWork.UserRepository.Update(user);
 }
Esempio n. 6
0
 public void UpdateLastActivity(User user)
 {
     user.LastActivity = DateTime.Now;
     UpdateUser(user);
     Save();
 }
Esempio n. 7
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid) {
                // Attempt to register the user

                var newUser = new User { UserName = model.UserName, Email = model.Email };
                bool isUserCreated = _securityService.CreateUser(newUser, model.Password);
                if (isUserCreated) {
                    FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false);
                    return RedirectToAction("Index", "Home");
                } else {
                    ModelState.AddModelError("", "Error Registering");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }