コード例 #1
0
 public User UpdateUser(User user)
 {
     var existingUser = GetByUsername(user.UserName);
     if(existingUser != null)
     {
         existingUser = user;
         _context.SaveChanges();
     }
     return existingUser;
 }
コード例 #2
0
        public User CreateUser(string username, byte[] passwordSalt, byte[] passwordHash, UserDetails userDetails)
        {
            var user = new User()
            {
                Hash = passwordHash,
                Salt = passwordSalt,
                UserName = username,
                IsAdmin = false,
                UserDetails = userDetails
            };

            _context.Users.Add(user);
            _context.SaveChanges();

            return user;
        }
コード例 #3
0
        private static FormsAuthenticationTicket CreateAuthenticationTicket(User user, bool isPersistent, HttpContextBase context)
        {
            var expirationDate = isPersistent
                ? DateTime.Now.AddDays(30)
                : DateTime.Now.AddMinutes(
                (context == null || context.Session == null) ? 20 : context.Session.Timeout);

            var ticket = new FormsAuthenticationTicket(
                1,
                user.UserName,
                DateTime.Now,
                expirationDate,
                isPersistent,
                string.Empty);

            return ticket;
        }
コード例 #4
0
 public Response<User> UpdateUser(User user)
 {
     return new Response<User> { Entity = _userRepository.UpdateUser(user) };
 }
コード例 #5
0
        public ActionResult Index(UserViewModel viewModel)
        {
            var login = _userService.Login(viewModel.Username, viewModel.Password);

            if(login.Success)
            {
                _authenticationService.LoginUser(login.Entity, HttpContext, false);

                CurrentUser = HttpContext.User as User;

                if(login.Entity.IsAdmin)
                {
                    return RedirectToAction("Admin");
                }

                return RedirectToAction("Profile");
            }

            ModelState.AddModelError("username", login.Error.ToString());
            return View();
        }