public async Task <ActionResult> Register(RegisterViewModel model) { await SetInitialDataAsync(); if (ModelState.IsValid) { ApplicationUserDTO applicationUserDTO = new ApplicationUserDTO { Email = model.Email, Password = model.Password, //Address = model.Address, //Name = model.Name, RolesID = { 1 } }; OperationDetails operationDetails = await ApplicationUserService.Create(applicationUserDTO); if (operationDetails.Succedeed) { return(View("SuccessRegister")); } else { ModelState.AddModelError(operationDetails.Property, operationDetails.Message); } } return(View(model)); }
public Task <ApplicationUserOut> CreateUser( [CurrentUserGlobalState] CurrentUser user, [Service] ApplicationUserService service) => service.Create(new ApplicationUserOut { ExternalId = user.UserId, Username = "******", Email = "*****@*****.**" });
public async Task CreateWithoutPassword() { var username = "******"; var email = "[email protected]"; var firstName = "first"; var lastName = "name"; var dbUserId = await ApplicationUserService.Create(username, email, firstName, lastName); Assert.AreNotEqual(new Guid().ToString(), dbUserId); Assert.IsNullOrEmpty(dbUserId.PasswordHash); }
private async Task CreateUserWithPassword(int i, string username) { if (i > 0) { username += i; } var email = $"{username}@lunchorder.be"; var name = username.Split('_'); var firstName = name[0]; var lastName = name[1]; var dbUserId = await ApplicationUserService.Create(username, email, firstName, lastName, password : username); Assert.AreNotEqual(new Guid().ToString(), dbUserId); Assert.IsNotNullOrEmpty(dbUserId.PasswordHash); }
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { // Enable the application to use a cookie to store information for the signed in user // and to use a cookie to temporarily store information about a user logging in with a third party login provider // Configure the sign in cookie app.CreatePerOwinContext <ApplicationUserService>((options, context) => ApplicationUserService.Create(options, context)); app.CreatePerOwinContext <ApplicationSignInService>((options, context) => ApplicationSignInService.Create(options, context)); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login"), Provider = new CookieAuthenticationProvider() }); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process. app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); // Enables the application to remember the second login verification factor such as phone or email. // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from. // This is similar to the RememberMe option when you log in. app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); // Uncomment the following lines to enable logging in with third party login providers //app.UseMicrosoftAccountAuthentication( // clientId: "", // clientSecret: ""); //app.UseTwitterAuthentication( // consumerKey: "", // consumerSecret: ""); //app.UseFacebookAuthentication( // appId: "", // appSecret: ""); //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() //{ // ClientId = "", // ClientSecret = "" //}); }
public async Task Should_Create_Valid_User() { // Arrange var repo = Substitute.For <IApplicationUserRepository>(); var service = new ApplicationUserService(repo, Mock.Mapper); var model = new ApplicationUserDto { FirstName = "Trung", LastName = "Test", Email = "*****@*****.**", ContactNumber = "0349049xxx", Password = "******" }; // Act var result = await service.Create(model); // Assert await repo.Received(1).Add(Arg.Is <ApplicationUser>(x => x.Email == model.Email)); }