public void RegisterReturnsBadResultIfUserManagerReturnsFailure() { var userStore = new Mock <IUserStore <ApplicationUser> >(); var userManager = new Mock <ApplicationUserManager>(userStore.Object); var authManager = new Mock <IAuthenticationManager>(); var signInManager = new Mock <ApplicationSignInManager>(userManager.Object, authManager.Object); var controller = new AccountController(userManager.Object, null, null, signInManager.Object); var model = new Models.RegisterBindingModel() { Email = "*****@*****.**", Password = "******", ConfirmPassword = "******" }; userManager.Setup(u => u.CreateAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>())) .Callback <ApplicationUser, string>((user, password) => { Assert.AreEqual(model.Email, user.Email); Assert.AreEqual(model.Password, password); }) .ReturnsAsync(new IdentityResult("Invalid DB access")); var result = controller.Register(model); result.Wait(); var view = result.Result; Assert.That(view is System.Web.Http.Results.InvalidModelStateResult); userStore.VerifyAll(); userManager.VerifyAll(); authManager.VerifyAll(); signInManager.VerifyAll(); }
public void RegisterReturnsBadResultIfRequestIsInvalid(string userName, string password, string confirmPassword) { var userStore = new Mock <IUserStore <ApplicationUser> >(); var userManager = new Mock <ApplicationUserManager>(userStore.Object); var authManager = new Mock <IAuthenticationManager>(); var signInManager = new Mock <ApplicationSignInManager>(userManager.Object, authManager.Object); var controller = new AccountController(userManager.Object, null, null, signInManager.Object); var model = new Models.RegisterBindingModel() { Email = userName, Password = password, ConfirmPassword = confirmPassword }; var result = controller.Register(model); result.Wait(); var view = result.Result; Assert.That(view is System.Web.Http.Results.InvalidModelStateResult); userStore.VerifyAll(); userManager.VerifyAll(); authManager.VerifyAll(); signInManager.VerifyAll(); }
public async Task <IHttpActionResult> Register(Models.RegisterBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser() { UserName = model.Email, Email = model.Email, Firstname = model.Firstname, Lastname = model.Lastname }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (!result.Succeeded) { return(GetErrorResult(result)); } RegionEndpoint regionep = Amazon.RegionEndpoint.GetBySystemName(System.Web.Configuration.WebConfigurationManager.AppSettings["region"]); string awskey = System.Web.Configuration.WebConfigurationManager.AppSettings["awskey"]; string awssecret = System.Web.Configuration.WebConfigurationManager.AppSettings["awssecret"]; string arn = System.Web.Configuration.WebConfigurationManager.AppSettings["awssnstopic"]; Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient simp = new Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient(awskey, awssecret, new Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceConfig { RegionEndpoint = regionep }); simp.Subscribe(arn, "email", model.Email); simp.PublishAsync(arn, "Please welcome to Tune World " + model.Firstname + " " + model.Lastname, "Tune World Registration"); return(Ok()); }
public static async Task <bool> RegisterUserAsync(string login, string email, string password, string firstname, string lastname, string birthdate) { bool Response = false; await Task.Run(() => { var client = new HttpClient(); var model = new Models.RegisterBindingModel { Login = login, Email = email, Password = password, FirstName = firstname, LastName = lastname, BirthDate = birthdate }; var json = JsonConvert.SerializeObject(model); HttpContent httpContent = new StringContent(json); httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); var response = client.PostAsync(URI + "api/Users/Register", httpContent); if (response.Result.IsSuccessStatusCode) { Response = true; } }); return(Response); }
public async Task Two() { var controller = new Controllers.Api.AccountController(); var model = new Models.RegisterBindingModel() { UserName = "******", Email = "test", Password = "******", ConfirmPassword = "******" }; var response = await controller.Register(model); }
public async Task RegisterUser_ReturnExpected() { var controller = new UsersController(this.manager); var model = new Models.RegisterBindingModel { UserName = "******", Email = "*****@*****.**", Password = "******", ConfirmPassword = "******" }; var result = await controller.Register(model); Assert.IsNotNull(result); Assert.IsInstanceOf <CreatedNegotiatedContentResult <UserInfo> >(result); var content = (result as CreatedNegotiatedContentResult <UserInfo>).Content; Assert.AreEqual(model.UserName, content.Name); Assert.AreEqual(500, content.Balance); }
public ActionResult Registracija(Models.RegisterBindingModel model) { if (ModelState.IsValid) { //Debug.WriteLine(model.ime + " " + model.prezime + " " + model.Password + " " + model.Email); using (ppij_databaseEntities data = new ppij_databaseEntities()) { if (data.Osoba.Where(o => o.korisnicko_ime_osoba == model.korisnicko_ime).Count() != 0) { ModelState.AddModelError("kor_ime_uniq", "Odabrano korisničko ime već postoji"); return(View()); } string salt = Crypto.GenerateSalt(12); Osoba osoba = new Osoba(); osoba.ime_osoba = model.ime; osoba.prezime_osoba = model.prezime; osoba.korisnicko_ime_osoba = model.korisnicko_ime; osoba.lozinka = Crypto.HashPassword(model.Password + salt); osoba.salt = salt; /*if (model.jeInstruktor == true) * { * osoba.razina_prava = 1; * } * else * {*/ osoba.razina_prava = 2; /*}*/ osoba.email_osoba = model.Email; osoba.ID_osoba = data.Osoba.OrderByDescending(o => o.ID_osoba).FirstOrDefault().ID_osoba + 1; osoba.dogovor_termin = null; osoba.dogovor_termin1 = null; osoba.osoba_predmet = null; osoba.Termin = null; data.Osoba.Add(osoba); //Debug.WriteLine(osoba.ID_osoba + " " + osoba.ime_osoba + " " + osoba.prezime_osoba + " " + osoba.korisnicko_ime_osoba + " " + osoba.lozinka); try { data.SaveChanges(); } catch (SqlException sqle) { foreach (SqlErrorCollection errors in sqle.Errors) { Debug.WriteLine(errors.ToString()); } } catch (DbEntityValidationException deve) { foreach (var validationErrors in deve.EntityValidationErrors) { foreach (var error in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", error.PropertyName, error.ErrorMessage); } } } FormsAuthentication.SetAuthCookie(osoba.korisnicko_ime_osoba, false); return(RedirectToAction("Index", "Home")); } } return(View()); }