Exemplo n.º 1
0
 public async Task<CreateUserOutput> CreateUser(CreateUserInput input)
 {
     CreateUserOutput result = await _userBll.CreateUser(input);
     if (result.Status == 0)
     {
         int num = await this._permissionBll.GenerateRolesForUser(input.Id);
     }
     return result;
 }
Exemplo n.º 2
0
 public async Task<CreateUserOutput> CreateUser(CreateUserInput input)
 {
     CreateUserOutput result = new CreateUserOutput();
     result.Status = 1;
     ApplicationUser user = new ApplicationUser();
     user.Email = input.Email;
     user.UserName = input.UserName;
     user.PhoneNumber = input.PhoneNumber;
     IdentityResult validateUserResult = await this.UserManager.UserValidator.ValidateAsync(user);
     IdentityResult validatePassResult = await this.UserManager.PasswordValidator.ValidateAsync(input.Password);
     if (validateUserResult.Succeeded && validatePassResult.Succeeded)
     {
         IdentityResult res = await this.UserManager.CreateAsync(user);
         if (res.Succeeded)
         {
             input.Id = user.Id;
             if (!string.IsNullOrEmpty(input.Password))
             {
                 res = await this.UserManager.AddPasswordAsync(user.Id, input.Password);
                 if (res.Succeeded)
                 {
                     if (!string.IsNullOrEmpty(input.DisplayName))
                         res = await this.UserManager.AddClaimAsync(user.Id, new Claim("displayName", input.DisplayName));
                     if (input.UserGroups != null)
                     {
                         foreach (Quang.Auth.Entities.Group group in input.UserGroups)
                             this._userTable.addUserToGroup(group.Id, user.Id);
                     }
                     result.Status = 0;
                 }
                 else
                 {
                     IdentityResult identityResult = await this.UserManager.DeleteAsync(user);
                 }
             }
             else
                 result.Status = 0;
         }
     }
     return result;
 }
Exemplo n.º 3
0
 public async Task<CreateMobileUserOutput> CreateMobileUser(CreateMobileUserInput minput)
 {
     CreateMobileUserOutput output = new CreateMobileUserOutput()
     {
         Status = 1
     };
     ApplicationUser currentUser = await this.UserManager.FindByNameAsync(minput.Mobile);
     if (currentUser != null && currentUser.Id > 0)
     {
         output.MobileMsg = ConfigurationManager.AppSettings["SmsMsgRegistErrorExist"];
     }
     else
     {
         string password = this.GeneratePassword(6);
         CreateUserInput input = new CreateUserInput()
         {
             UserName = minput.Mobile,
             DisplayName = minput.Mobile,
             PhoneNumber = minput.Mobile,
             Password = password,
             ConfirmPassword = password
         };
         CreateUserOutput res = await this.CreateUser(input);
         if (res.Status == 0)
         {
             output.Status = 0;
             output.MobileMsg = string.Format(ConfigurationManager.AppSettings["SmsMsgRegistSuccess"], (object)password);
         }
         else
             output.MobileMsg = ConfigurationManager.AppSettings["SmsMsgRegistErrorUnknown"];
     }
     return output;
 }