public async Task <RegisterResult> RegisterExternalAsync(string username, string email, string scheme, string identity, string identityName) { var user = new LoginUser() { Username = username, Email = email, CreationTime = DateTime.UtcNow }; var userAuth = new LoginUserAuthentication() { Scheme = StringToScheme(scheme), Identity = identity, Name = identityName, CreationTime = DateTime.UtcNow }; try { user = await _persistence.Users.CreateUserAsync(user); } catch (Exception) { //TODO reduce breadth of exception statement return(RegisterResult.GetFailed("Username is already in use")); } try { userAuth.UserId = user.Id; userAuth = await _persistence.Users.CreateUserAuthenticationAsync(userAuth); } catch (Exception) { // cleanup await _persistence.Users.DeleteUserAsync(user); throw; } // add in option of an email activation step and use options to provide redirect url await SignInAsync(user); return(RegisterResult.GetSuccess()); }
public async Task <AuthenticationDetails> AddAuthenticationAsync(string userId, string scheme, string identity, string identityName) { var userAuth = new LoginUserAuthentication() { UserId = userId, Scheme = StringToScheme(scheme), Identity = identity, Name = identityName, CreationTime = DateTime.UtcNow }; userAuth = await _persistence.Users.CreateUserAuthenticationAsync(userAuth); return(new AuthenticationDetails() { Id = userAuth.Id, Scheme = userAuth.Scheme.ToString(), Identity = userAuth.Identity, Name = userAuth.Name, CreationTime = userAuth.CreationTime }); }