public ActionResult Register(AppUserVM apvm) { if (!ModelState.IsValid) { return(View("Register")); } apvm.AppUser.Password = DantexCrypt.Crypt(apvm.AppUser.Password); apvm.AppUser.ConfirmPassword = DantexCrypt.Crypt(apvm.AppUser.ConfirmPassword); if (apRep.Any(x => x.Email == apvm.AppUser.Email)) { ViewBag.Mevcut = "Bu Email adresine kayıtlı hesap bulunmaktadır."; return(View()); } string gonderilecekMail = "Tebrikler kayıt olma işleminiz başarılı bir şekilde gerçekleştirilmiştir. Hesabınızı aktif etmek için https://localhost:44390/Account/Activation/" + apvm.AppUser.ActivationCode + " linkine tıklamanız yeterlidir."; MailSender.Send(apvm.AppUser.Email, body: gonderilecekMail, subject: "Hesap Aktivasyon"); apRep.Add(apvm.AppUser); //One to one relation on first if (!string.IsNullOrEmpty(apvm.UserProfile.FirstName) || !string.IsNullOrEmpty(apvm.UserProfile.LastName) || apvm.UserProfile.Gender != 0 || !string.IsNullOrEmpty(apvm.UserProfile.MobilePhone)) { apvm.UserProfile.ID = apvm.AppUser.ID; apdRep.Add(apvm.UserProfile); } return(View("RegisterOk")); }
public async Task <OperationDetails> Create(DutUser userDto, string password) { var user = await UserManager.FindByEmailAsync(userDto.Email); if (user != null) { return(new OperationDetails(false, "Користувач з таким email вже існує", "Email")); } var result = await UserManager.CreateAsync(userDto, password); if (result.Errors.Any()) { return(new OperationDetails(false, result.Errors.FirstOrDefault(), "")); } // Добавить роль await UserManager.AddToRoleAsync(userDto.Id, "user"); // Создание профиля клиента ClientProfile clientProfile = new ClientProfile { Id = userDto.Id, FullName = userDto.ClientProfile.FullName }; UserProfileRepository.Add(clientProfile); await SaveUser(); return(new OperationDetails(true, "Реєстрація успішно пройдена", "")); }
public IActionResult Register(UserProfile userProfile) { // All newly registered users start out as a "user" user type (i.e. they are not admins) _userProfileRepository.Add(userProfile); return(CreatedAtAction( nameof(GetByFirebaseUserId), new { firebaseUserId = userProfile.FirebaseUserId }, userProfile)); }
public ActionResult RegisterNow(AppUserVM apvm) { AppUser appUser = apvm.AppUser; UserProfile profile = apvm.Profile; appUser.Password = DantexCrypt.Crypt(appUser.Password); //sifreyi kriptoladık //AppUser.Password = DantexCrypt.DeCrypt(apvm.AppUser.Password); if (apRep.Any(x => x.UserName == appUser.UserName)) { ViewBag.ZatenVar = "This username is already taken"; return(View()); } else if (apRep.Any(x => x.Email == appUser.Email)) { ViewBag.ZatenVar = "This email is already registered"; return(View()); } //Kullanıcı basarılı bir şekilde register işlemini tamamladıysa ona mail gönder string gonderilecekMail = "Congratulations...Your account has been created. You can click the https://localhost:44362/Register/Activation/" + appUser.ActivationCode + " link to activate your account.."; MailSender.Send(appUser.Email, body: gonderilecekMail, subject: "Account activation!"); apRep.Add(appUser); //öncelikle bunu eklemelisiniz. Cnkü AppUser'in ID'si ilk basta olusmalı... Cünkü biz birebir ilişkide AppUser zorunlu alan Profile ise opsiyonel alandır. Dolayısıyla ilk basta AppUser'in ID'si SaveChanges ile olusmalı ki sonra Profile'i rahatca ekleyebilelim... if (!string.IsNullOrEmpty(profile.FirstName) || !string.IsNullOrEmpty(profile.LastName) || !string.IsNullOrEmpty(profile.Address)) { profile.ID = appUser.ID; apdRep.Add(profile); } return(View("RegisterOk")); }
public void User_Can_Add_UserProfile() { var repo = new UserProfileRepository(_context); var startingUsers = repo.GetAll(); var startingCount = startingUsers.Count; var newUser = new UserProfile() { UserName = "******", Email = "*****@*****.**", ImageUrl = "image.jpeg", FirebaseUserId = "TEST_FIREBASE_UID_2" }; //add new user repo.Add(newUser); //Get all snags again var resultingUsers = repo.GetAll(); var resultingCount = resultingUsers.Count; //Check that one has been added Assert.NotEqual(0, newUser.Id); Assert.Equal(startingCount + 1, resultingCount); }
public ActionResult RegisterNow(AppUserVM apvm) { AppUser appUser = apvm.AppUser; UserProfile profile = apvm.Profile; appUser.Password = DantexCrypt.Crypt(appUser.Password); if (apRep.Any(x => x.UserName == appUser.UserName)) { ViewBag.ZatenVar = "Kullanici ismi daha onceden alinmis"; return(View()); } else if (apRep.Any(x => x.Email == appUser.Email)) { ViewBag.ZatenVar = "Email adresi daha onceden alinmis"; return(View()); } string gonderilecekMail = "Tebrikler. Hesabiniz olusturuldu. Hesabinizi aktif etmek icin lutfen baglantiya tiklayin. https://localhost:44318/Register/Activation/" + appUser.ActivationCode; MailSender.Send(appUser.Email, password: "******", body: gonderilecekMail, subject: "Hesap Aktivasyon", sender: "*****@*****.**"); apRep.Add(appUser); if (!string.IsNullOrEmpty(profile.FirstName) || !string.IsNullOrEmpty(profile.LastName)) { profile.ID = appUser.ID; apdRep.Add(profile); } return(View("RegisterOk")); }
public IActionResult Register(UserProfile userProfile) { userProfile.CreateDateTime = DateTime.Now; _userProfileRepository.Add(userProfile); return(CreatedAtAction( nameof(GetByFirebaseUserId), new { firebaseUserId = userProfile.FirebaseUserId }, userProfile)); }
public IActionResult Post(UserProfile userProfile) { userProfile.CreateDateTime = DateTime.Now; userProfile.UserTypeId = UserType.AUTHOR_ID; _userProfileRepository.Add(userProfile); return(CreatedAtAction( nameof(GetUserProfile), new { firebaseUserId = userProfile.FirebaseUserId }, userProfile)); }
public IActionResult Post(UserProfile userProfile) { userProfile.CreateDateTime = DateTime.Now; userProfile.IsActivated = true; _userProfileRepository.Add(userProfile); return(CreatedAtAction( nameof(GetUserProfile), new { firebaseUserId = userProfile.FirebaseUserId }, userProfile)); }
public IHttpActionResult UpdateProfile(UserProfileModel model) { try { if (model != null) { UserProfile profile = new UserProfile { UserId = model.UserId, FirstName = model.FirstName, LastName = model.LastName, Gender = model.Gender, Email = model.Email, Phone = model.Phone, Mobile = model.Mobile, Street = model.Street, City = model.City, Image = model.Image, Location = model.Location, LocationLatitude = model.LocationLatitude, LocationLongitude = model.LocationLongitude, ContactMethod = model.ContactMethod, BankId = model.BankId, BankBranch = model.BankBranch, AccountName = model.AccountName, AccountNo = model.AccountNo, NotificationFrequencyMinutes = model.NotificationFrequencyMinutes }; using (AppDBContext context = new AppDBContext()) { var repo = new UserProfileRepository(context); var existing = repo.GetByUserId(profile.UserId); if (existing == null) { repo.Add(profile); } else { repo.Update(profile); } } } return(Ok()); } catch (Exception ex) { Logger.Log(typeof(UserController), ex.Message + ex.StackTrace, LogType.ERROR); return(InternalServerError()); } }
public IActionResult Post(RegisterViewModel registerview) { var userTypeUser = 2; var organization = _organizationRepo.GetByOrganizationUID(registerview.OrganizationCode); var user = new UserProfile() { Name = registerview.Name, OrganizationId = organization.Id, Email = registerview.Email, FirebaseUserId = registerview.FirebaseUserId, UserTypeId = userTypeUser }; _userRepo.Add(user); return(CreatedAtAction("Get", new { FirebaseId = user.FirebaseUserId }, user)); }
public void UserRepository_AddItem_IsNotNullWhenGet() { var dbData = new DalUserProfile { Id = 100, Email = "mail1", Name = "name1", Password = "******" }; var dbSetMock = new Mock<DbSet<OrmUserProfile>>(); var dbContextMock = new Mock<EntityModelContext>(); dbContextMock.Setup(x => x.Set<OrmUserProfile>()).Returns(dbSetMock.Object); var repo = new UserProfileRepository(dbContextMock.Object); repo.Add(dbData); Assert.IsNotNull(repo.Get(100)); }
public static void SeedAdminAccount(this DutContext context, string userName, string passaword) { var userManager = new UserManager <DutUser>(new UserStore <DutUser>(context)); var user = userManager.Find(userName, passaword); if (user != null) { return; } SeedUserRoles(context, new List <string> { "admin", "user" }); user = new DutUser { UserName = userName }; var result = userManager.Create(user, passaword); if (result.Succeeded) { var factory = new DataBaseFactory(); factory.Get(); userManager.AddToRole(user.Id, "admin"); var m = new UserProfileRepository(factory); m.Add(new ClientProfile { Id = user.Id, Enable = true, CreateDate = DateTime.Now }); factory.Get().SaveChanges(); } else { var e = new Exception("Could not add default account"); var enumerator = result.Errors.GetEnumerator(); foreach (var resultError in result.Errors) { e.Data.Add(enumerator.Current, resultError); } throw e; } }
public void UserRepository_AddItem_IsNotNullWhenGet() { var dbData = new DalUserProfile { Id = 100, Email = "mail1", Name = "name1", Password = "******" }; var dbSetMock = new Mock <DbSet <OrmUserProfile> >(); var dbContextMock = new Mock <EntityModelContext>(); dbContextMock.Setup(x => x.Set <OrmUserProfile>()).Returns(dbSetMock.Object); var repo = new UserProfileRepository(dbContextMock.Object); repo.Add(dbData); Assert.IsNotNull(repo.Get(100)); }
public async Task <ActionResult> SignUp(AccountSignUpViewModel viewModel) { if (ModelState.IsValid) { var existingUser = await _userManager.FindByEmailAsync(viewModel.Email); if (existingUser != null) { ModelState.AddModelError("Email", "The provided email address has already been used."); } else { var user = new User { UserName = viewModel.Email, Email = viewModel.Email }; var result = await _userManager.CreateAsync(user, viewModel.Password); if (result.Succeeded) { var userProfile = new UserProfile { FullName = viewModel.FullName, JoinDate = DateTime.Today, UserId = user.Id }; _userProfileRepository.Add(userProfile); await _signInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); return(RedirectToAction("Index", "Member")); } foreach (var error in result.Errors) { ModelState.AddModelError("", error); } } } return(View(viewModel)); }
public ActionResult RegisterNow(AppUserVM apvm) { if (!ModelState.IsValid) { return(View("RegisterNow")); } AppUser appUser = apvm.AppUser; UserProfile profile = apvm.UserProfile; appUser.Password = DantexCrypt.Crypt(appUser.Password); appUser.ConfirmPassword = DantexCrypt.Crypt(appUser.ConfirmPassword); //Kayıt işlemi if (apRep.Any(x => x.UserName == appUser.UserName)) { ViewBag.ZatenVar = "Kullanıcı ismi alınmış"; return(View()); } else if (apRep.Any(x => x.Email == appUser.Email)) { ViewBag.ZatenVar = "Email kayıtlı"; return(View()); } //Başarılı kayıt sonrası mail gönderme işlemi string register = "Tebrikler, hesabınız oluşturulmuştur. Hesabınızı aktive etmek için https://localhost:44317/Register/Activation/" + appUser.ActivationCode + " linkine tıklayabilirsiniz."; MailSender.Send(appUser.Email, body: register, subject: "Hesap Aktivasyon!"); apRep.Add(appUser); if (!string.IsNullOrEmpty(profile.FirstName) || !string.IsNullOrEmpty(profile.LastName) || !string.IsNullOrEmpty(profile.Address) || !string.IsNullOrEmpty(profile.Phone)) { profile.ID = appUser.ID; usRep.Add(profile); } return(View("RegisterSuccess")); }
public async Task <IActionResult> Register(UserProfile newUser) { if (_userProfileRepository.GetByEmail(newUser.Email) == null) { try { newUser.CreateDateTime = DateAndTime.Now; newUser.UserTypeId = 2; _userProfileRepository.Add(newUser); } catch { return(View()); } var registeredUser = _userProfileRepository.GetByEmail(newUser.Email); var claims = new List <Claim> { new Claim(ClaimTypes.NameIdentifier, registeredUser.Id.ToString()), new Claim(ClaimTypes.Email, registeredUser.Email), new Claim(ClaimTypes.Role, registeredUser.UserType.Name) }; var claimsIdentity = new ClaimsIdentity( claims, CookieAuthenticationDefaults.AuthenticationScheme); await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity)); return(RedirectToAction("Index", "Home")); } return(View()); }
public async Task <IActionResult> Post(UserProfile userProfile) { await _userProfileRepository.Add(userProfile); return(Ok(userProfile)); }
public IActionResult UserProfile(UserProfile post) { _profileRepository.Add(post); return(CreatedAtAction("Get", new { id = post.Id }, post)); }
public IActionResult Post(UserProfile userProfile) { _userProfileRepository.Add(userProfile); return(CreatedAtAction("Get", new { id = userProfile.Id }, userProfile)); }