protected override IdentityUserLogin <string> CreateUserLogin(MrsMobileUser user, UserLoginInfo login) => new IdentityUserLogin <string> { UserId = user.Id, ProviderKey = login.ProviderKey, LoginProvider = login.LoginProvider, ProviderDisplayName = login.ProviderDisplayName, };
protected override IdentityUserClaim <string> CreateUserClaim(MrsMobileUser user, Claim claim) { var identityUserClaim = new IdentityUserClaim <string> { UserId = user.Id }; identityUserClaim.InitializeFromClaim(claim); return(identityUserClaim); }
public async Task <ActionResult <string> > Register([FromBody] UserRegisterBindingModel model) { if (model == null || !ModelState.IsValid || model.PhoneNumber.Length < 5) { return(BadRequest(ModelState.Values.FirstOrDefault())); } var accountSid = options.Value.AccountSid; var authToken = options.Value.AuthToken; var fromNumber = options.Value.PhoneNumber; var verificationCode = await smsService.SendSms(accountSid, authToken, fromNumber, model.PhoneNumber); if (string.IsNullOrEmpty(verificationCode)) { return(BadRequest()); } if (await userManager.FindByNameAsync(model.PhoneNumber) == null) { var deviceId = await deviceService.AddDeviceAsync(model.Device); var user = new MrsMobileUser { Email = model.PhoneNumber, UserName = model.PhoneNumber, PhoneNumber = model.PhoneNumber, DeviceId = deviceId }; var result = await userManager.CreateAsync(user, model.PhoneNumber); if (!result.Succeeded) { return(BadRequest(result.Errors.FirstOrDefault())); } var addRole = await userManager.AddToRoleAsync(user, GlobalConstants.RoleUser); if (!addRole.Succeeded) { return(BadRequest(addRole.Errors.FirstOrDefault())); } } var token = await smsAuthanticationService.AddSmsTokenAsync(userManager.FindByNameAsync(model.PhoneNumber).Result.Id, verificationCode); if (!string.IsNullOrEmpty(token)) { return(token); } return(BadRequest()); }
protected override IdentityUserToken <string> CreateUserToken( MrsMobileUser user, string loginProvider, string name, string value) { var token = new IdentityUserToken <string> { UserId = user.Id, LoginProvider = loginProvider, Name = name, Value = value, }; return(token); }
protected override IdentityUserRole <string> CreateUserRole(MrsMobileUser user, MrsMobileRole role) { return(new IdentityUserRole <string> { RoleId = role.Id, UserId = user.Id }); }