Пример #1
0
        public async Task LastLoginUpdate(CMSUser user)
        {
            var model = await this.usersRepository.GetUserByNameAsync(user.UserName);

            model.LastLoginTime = DateTime.Now;
            await usersRepository.UpdateAsync(user);
        }
Пример #2
0
        public async Task <bool> CreateAsync(UserViewModel model)
        {
            if (!modelState.IsValid)
            {
                return(false);
            }

            var existingUser = await this.usersRepository.GetUserByNameAsync(model.Username);

            if (existingUser != null)
            {
                modelState.AddModelError(string.Empty, "The user already exists");
                return(false);
            }
            if (!Regex.IsMatch(model.Username, @"^[a-zA-Z0-9]+$"))
            {
                modelState.AddModelError(string.Empty, "Username must be letter and number only");
                return(false);
            }
            if (string.IsNullOrWhiteSpace(model.NewPassword))
            {
                modelState.AddModelError(string.Empty, "Your must type a password");
                return(false);
            }
            if (model.NewPassword.Length < 6)
            {
                modelState.AddModelError(string.Empty, "Password Length must be greater than 6 ");
                return(false);
            }

            var newUser = new CMSUser()
            {
                UrlImage         = model.UrlImage,
                UserName         = model.Username,
                Email            = model.Username,
                Born             = DateTime.Now,
                RegistrationDate = DateTime.Now,
                Security         = model.Security,
                LastLoginTime    = DateTime.Now,
                DisplayName      = model.DisplayName,
                SlugUrl          = "fuuser" + Guid.NewGuid().ToString() + DateTime.Now.ToString("yymmssfff")
            };

            await usersRepository.CreateAsync(newUser, model.NewPassword);

            await usersRepository.AddUserToRoleAsync(newUser, model.SelectedRole);

            return(true);
        }
 public async Task <IEnumerable <string> > GetRolesForUserAsync(CMSUser user)
 {
     return(await manager.GetRolesAsync(user.Id));
 }
 public IEnumerable <string> GetRolesForUser(CMSUser user)
 {
     return(manager.GetRoles(user.Id));
 }
 public async Task AddUserToRoleAsync(CMSUser user, string role)
 {
     await manager.AddToRoleAsync(user.Id, role);
 }
 public async Task UpdateAsync(CMSUser user)
 {
     await manager.UpdateAsync(user);
 }
 public async Task DeleteAsync(CMSUser user)
 {
     await manager.DeleteAsync(user);
 }
 public async Task CreateAsync(CMSUser user, string password)
 {
     await manager.CreateAsync(user, password);
 }
 public async Task <ClaimsIdentity> CrateIdentityAsync(CMSUser user)
 {
     return(await manager.CreateIdentityAsync(
                user, DefaultAuthenticationTypes.ApplicationCookie));
 }
 public async Task RemoveUserFromRoleAsync(CMSUser user, params string[] roleNames)
 {
     await manager.RemoveFromRolesAsync(user.Id, roleNames);
 }