public Customer AddTypeBusiness(CustomerRegisterViewModel model, Guid idAccount) { var customer = Save(model, idAccount); var typeBusiness = new TypeBusiness() { IdAccount = idAccount, IdCustomer = customer.Id, Name = model.NewTypeBusiness, StatusRegister = CStatusRegister.Active }; _typeBusinessDao.InsertOrUpdate(typeBusiness); return(customer); }
public RegisterCustomerResult RegisterCustomer(CustomerRegisterViewModel registerCustomerViewModel) { var customerModel = new Customer() { Gender = (int)registerCustomerViewModel.Gender, Name = registerCustomerViewModel.Name, Phone = registerCustomerViewModel.Phone, PhotoUrl = registerCustomerViewModel.PhotoUrl, }; _customerRepository.Add(customerModel); _customerRepository.SaveChanges(); return(RegisterCustomerResult.OK); }
public Customer AddProductCategory(CustomerRegisterViewModel model, Guid idAccount) { var customer = Save(model, idAccount); var productCategory = new ProductCategory() { Name = model.NewCategories, Code = _sequenceBusiness.NextSequence(CProductCategory.SequenceCode, idAccount).ToString(), IdCustomer = customer.Id, StatusRegister = CStatusRegister.Active }; _productCategoryDao.InsertOrUpdate(productCategory); return(customer); }
public Customer AddChannel(CustomerRegisterViewModel model, Guid idAccount) { var customer = Save(model, idAccount); var channel = new Channel() { IdAccount = idAccount, IdCustomer = customer.Id, Name = model.NewChannels, StatusRegister = CStatusRegister.Active }; _channelDao.InsertOrUpdate(channel); return(customer); }
public IActionResult Register(CustomerRegisterViewModel model) { if (!ModelState.IsValid) { return(BadRequest("Invalid Request")); } var customer = _customerService.CreateCustomer(model); if (customer == false) { return(StatusCode((int)HttpStatusCode.NotAcceptable, customer)); } return(Ok()); }
public bool CreateCustomer(CustomerRegisterViewModel model) { var customer = _mapper.Map <CustomerRegisterViewModel, Core.Models.Customer>(model); //map từ ViewModel qua Model bool firstletter = !Char.IsDigit(model.Username[0]); bool checkCustomer = _customerRepository.Get(x => x.Username.Equals(model.Username, StringComparison.Ordinal)) == null; bool checkInputOTP = _oTPRepository.Get(x => x.PhoneNo.Equals(model.PhoneNumber) && x.Code.Equals(model.OTPNumber) && x.ExpiredAtUTC > DateTime.UtcNow) != null; bool chackBackDoor = model.OTPNumber == "999999"; if (chackBackDoor && firstletter && checkCustomer) { byte[] salt = new byte[128 / 8]; using (var rng = RandomNumberGenerator.Create()) { rng.GetBytes(salt); } //Console.WriteLine($"Salt: {Convert.ToBase64String(salt)}"); customer.PasswordHash = HashPassword(customer.PasswordHash, salt); customer.SaltPasswordHash = Convert.ToBase64String(salt); customer.CreatedAtUTC = DateTime.UtcNow; customer.UpdatedAtUTC = DateTime.UtcNow; customer.IsActive = true; _customerRepository.Add(customer); _unitOfWork.CommitChanges(); return(true); } else if (checkInputOTP && firstletter && checkCustomer) { byte[] salt = new byte[128 / 8]; using (var rng = RandomNumberGenerator.Create()) { rng.GetBytes(salt); } //Console.WriteLine($"Salt: {Convert.ToBase64String(salt)}"); customer.PasswordHash = HashPassword(customer.PasswordHash, salt); customer.SaltPasswordHash = Convert.ToBase64String(salt); customer.CreatedAtUTC = DateTime.UtcNow; customer.UpdatedAtUTC = DateTime.UtcNow; customer.IsActive = true; _customerRepository.Add(customer); _unitOfWork.CommitChanges(); return(true); } return(false); }
public BusinessLayerResult <Customer> RegisterCustomer(CustomerRegisterViewModel data) { // Kullanıcı user kontrolü // Kullanıcı e-posta kontrolü // Kayıt işlemi // Aktivasyon e-postası gönderimi User user = repo_user.Find(x => x.mail == data.mail); BusinessLayerResult <Customer> res = new BusinessLayerResult <Customer>(); if (user != null) { if (user.mail == data.mail) { res.AddError(Entities.Messages.ErrorMessageCode.EMailAlreadyExists, "E-Posta adresi kayıtlı."); } } else { int dbResult = Insert(new Customer() { user_name = data.user_name, user_surname = data.user_surname, mail = data.mail, user_picturepath = "user_def.png", password = data.password, user_regdate = DateTime.Now, ActivateGuid = Guid.NewGuid(), notifications = new List <Notification>() }); if (dbResult > 0) { res.Result = Find(x => x.mail == data.mail); string siteUri = ConfigHelper.Get <string>("SiteRootUri"); string activateUri = $"{siteUri}/Home/CustomerActivate/{res.Result.ActivateGuid}"; string body = $"Merhaba {res.Result.user_name}; !<br><br>Hesabını aktifleştirmek için <a href='{activateUri}' target='_blank'>tıklayınız</a>."; MailHelper.SendMail(body, res.Result.mail, "Online Test Platform Hesap Aktifleştirme"); } } return(res); }
public async Task <IActionResult> Register(CustomerRegisterViewModel vm) { if (ModelState.IsValid) { //Add a new Customer IdentityUser user = new IdentityUser(vm.UserName); user.Email = vm.Email; IdentityResult result = await _userManagerService.CreateAsync(user, vm.Password); if (result.Succeeded) { Customer cust = new Customer { FirstName = vm.FirstName, LastName = vm.LastName, Email = vm.Email, Username = vm.UserName, Password = vm.Password, ConfirmPassword = vm.ConfirmPassword, Address = vm.Address, Suburb = vm.Suburb, State = vm.State, Postcode = vm.Postcode }; //Save to db _customerService.Create(cust); //Return to home page return(RedirectToAction("Index", "Home")); } else { //Display error foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } } return(View(vm)); }
public ActionResult SendRegister(CustomerRegisterViewModel model) { if (ModelState.IsValid) { var dao = new UserDAO(); var cdao = new CustomerDAO(); var result = dao.GetByUsername(model.Username); if (result != null) { ModelState.AddModelError("", "Tên đăng nhập đã tồn tại"); } else { User newUser = new User(); Customer newCustomer = new Customer(); newUser.UserID = dao.getNewID(); newUser.UserName = model.Username; newUser.Password = model.Password; newUser.CreatedByDate = DateTime.Now; newUser.RoleID = "RL-003"; dao.Insert(newUser); newCustomer.CustomerID = cdao.getNewID(); newCustomer.CustomerName = model.CustomerName; newCustomer.CustomerAddress = model.Address; newCustomer.Birth = model.Birth; newCustomer.PhoneNumber = model.PhoneNumber; newCustomer.Email = model.Email; newCustomer.Gender = model.Gender; newCustomer.UserID = newUser.UserID; cdao.Insert(newCustomer); var customerSession = new CustomerLogin(); customerSession.UserID = newUser.UserID; customerSession.UserName = newUser.UserName; Session.Add(CommonConstants.CUSTOMER_SESSION, customerSession); return(RedirectToAction("Index", "Home")); } } return(View("Register")); }
public static Customer FromCustomerRegisterViewModel(CustomerRegisterViewModel model) { return(new Customer() { Id = model.Id, Abbreviation = model.Abbreviation, Channels = (List <Channel>)model.Channels, Code = model.Code, Name = model.Name, Contact = model.Contact, Email = model.Email, DateCreation = model.DateCreation, Phone = model.Phone, StatusRegister = "A", IdTypeCustomer = model.IdTypeCustomer, IdStatusCustomer = model.IdStatusCustomer, ProductCategories = model.ProductCategories, TypeBusiness = model.TypeBusinessList }); }
public void LogIn(CustomerRegisterViewModel customerRegisterViewModel) { var CheckPhonenumber = unitOfWork.CustomerregisterRepository.Get().FirstOrDefault(x => x.CustomerPhone == customerRegisterViewModel.CustomerPhone); if (CheckPhonenumber != null) { var custpassword = unitOfWork.CustomerregisterRepository.Get().Where(m => m.CustomerPhone == customerRegisterViewModel.CustomerPhone).Select(k => k.Password).FirstOrDefault(); var data = Convert.FromBase64String(custpassword); using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()) { byte[] keys = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash)); using (TripleDESCryptoServiceProvider TripDes = new TripleDESCryptoServiceProvider() { Key = keys, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }) { ICryptoTransform transform = TripDes.CreateDecryptor(); byte[] result = transform.TransformFinalBlock(data, 0, data.Length); var DecriptPassword = UTF8Encoding.UTF8.GetString(result); var existingStatus = unitOfWork.CustomerregisterRepository.Get().FirstOrDefault(x => x.CustomerPhone == customerRegisterViewModel.CustomerPhone && DecriptPassword == customerRegisterViewModel.Password); var isDuplicateDescription = existingStatus != null; if (isDuplicateDescription) { customerRegisterViewModel.Errormessage = "Log In Successfull"; } else { customerRegisterViewModel.Errormessage = "Phone Number And Password Not Match"; } } } } else { customerRegisterViewModel.Errormessage = "Phone Number Are Not Match"; } }
public ActionResult CustomerRegister(CustomerRegisterViewModel model) { if (ModelState.IsValid) { CustomerManager cm = new CustomerManager(); BusinessLayerResult <Customer> res = cm.RegisterCustomer(model); if (res.Errors.Count > 0) { res.Errors.ForEach(x => ModelState.AddModelError("", x.Message)); return(View(model)); } OkViewModel ntfobj = new OkViewModel() { Title = "Kayıt Başarılı", RedirectingUrl = "/Home/CustomerLogin", }; ntfobj.Items.Add("Lütfen e-posta adresinize gönderdiğimiz aktivasyon linkine tıklayarak hesabınızı aktive ediniz.."); return(View("Ok", ntfobj)); } return(View(model)); }
public async Task <IActionResult> CustomerRegister(CustomerRegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var CustomerUser = new CustomerUser { UserName = model.Email, Email = model.Email, EmailAddress = model.EmailAddress, FirstName = model.FirstName, LastName = model.LastName, StreetAddress = model.StreetAddress, City = model.City, State = model.State, Zip = model.Zip, ProfileImage = model.ProfileImage }; var result = await _userManager2.CreateAsync(CustomerUser, model.Password); if (result.Succeeded) { // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); //await _emailSender.SendEmailAsync(model.Email, "Confirm your account", // $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>"); await _signInManager2.SignInAsync(CustomerUser, isPersistent : false); _logger.LogInformation(3, "User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult RegisterCustomer(CustomerRegisterViewModel model) { if (repo.GetAll().Where(x => x.Username == model.Username).FirstOrDefault() != null) { ModelState.AddModelError("", "Username already exists!"); } else if (ModelState.IsValid) { Customer customer = new Customer() { NID = model.NID }; repoCustomer.Insert(customer); repoCustomer.Submit(); Account account = new Account() { Name = model.Name, Password = model.Password, Username = model.Username, Email = model.Email, Mobile = model.Mobile, Gender = model.Gender, DateOfBirth = model.DateOfBirth, Address = model.Address, CustomerId = customer.Id, Customer = customer, ProfilePicture = "", UserType = 2 }; repo.Insert(account); repo.Submit(); return(Redirect("/")); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult CustomerRegister(CustomerRegisterViewModel model) { if (Request.HttpMethod == "POST") { if (!string.IsNullOrEmpty(model.Password) && !string.IsNullOrEmpty(model.ConfirmPassword) && (model.Password == model.ConfirmPassword)) { if (!dB.tbl_KhachHang.Any(d => d.UserName == model.UserName)) { tbl_KhachHang addKhachHang = new tbl_KhachHang(); addKhachHang.FullName = model.FullName; addKhachHang.UserName = model.UserName; addKhachHang.Password = model.Password; addKhachHang.PhoneNumber = model.PhoneNumber; addKhachHang.DiaChi = model.DiaChi; dB.tbl_KhachHang.Add(addKhachHang); dB.SaveChanges(); //redirect to Login CustomerLoginViewModel login = new CustomerLoginViewModel(); login.UserName = model.UserName; login.Password = model.Password; return(RedirectToAction("CustomerLogin", "Account", login)); } else { model.Error = "Tài khoản đã tồn tại"; } } else { return(View()); } } return(View(model)); }
public async Task <ActionResult> RegisterCustomer(CustomerRegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { //Luu thong tin dang ky vao table customer Customer customer = new Customer { Name = model.Name, Address = model.Address, Phone = model.Phone, Email = model.Email, UserId = user.Id }; db.Customers.Add(customer); db.SaveChanges(); //Gán role Customer cho user await UserManager.AddToRoleAsync(user.Id, "Customer"); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> RegisterCustomer(CustomerRegisterViewModel model) { var status = VerifyReCaptcha(); if (!status) { ModelState.AddModelError("", "Google reCaptcha validation failed"); } if (!model.IsCheck) { ModelState.AddModelError("", "Please review and accept Terms & Conditions."); } if (ModelState.IsValid && status) { var user = new ApplicationUser { UserName = model.Email.Trim().ToLower(), Email = model.Email.Trim().ToLower(), PhoneNumber = model.MobileNumber.Trim(), FirstName = model.FirstName.Trim().ToLower(), LastName = model.LastName.Trim().ToLower() }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { try { //1. Assign the user to a customer var customer = new Customer() { CustomerId = user.Id, DOB = model.DOB }; _context.Customers.Add(customer); _context.SaveChanges(); } catch (Exception ex) { throw; } //1.Get UserRoles //2.If Role is not there create //3.Assigns Customer to Customer Role //Assign Customer to user var getRole = _context.Roles.SingleOrDefault(c => c.Name.Contains(RoleName.Customer)); if (getRole == null) { //Temp code to create rolls and add user var roleStore = new RoleStore <IdentityRole>(new ApplicationDbContext()); //roll manager var roleManager = new RoleManager <IdentityRole>(roleStore); //to create the role await roleManager.CreateAsync(new IdentityRole(RoleName.Customer)); //Add User to the Role await UserManager.AddToRoleAsync(user.Id, RoleName.Customer); } else { //Add User to the Role await UserManager.AddToRoleAsync(user.Id, RoleName.Customer); } #region Create and Add Roles //Temp code to create rolls and add user //var roleStore = new RoleStore<IdentityRole>(new ApplicationDbContext()); ////roll manager //var roleManager = new RoleManager<IdentityRole>(roleStore); ////to create the role //await roleManager.CreateAsync(new IdentityRole(RoleName.Admin)); ////Add User to the Role //await UserManager.AddToRoleAsync(user.Id,RoleName.Admin); #endregion //Change this code to send confirmation email to users verus logging them in immediately //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); //await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); await UserManager.SendEmailAsync(user.Id, "Confirm your account", callbackUrl); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public void Register(CustomerRegisterViewModel customerRegisterViewModel) { var existingStatus = unitOfWork.CustomerregisterRepository.Get().FirstOrDefault(x => x.CustomerPhone == customerRegisterViewModel.CustomerPhone); var isDuplicateDescription = existingStatus != null; if (isDuplicateDescription) { customerRegisterViewModel.Errormessage = "Phone Number Are Exists"; } else { byte[] data = UTF8Encoding.UTF8.GetBytes(customerRegisterViewModel.Password); using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()) { byte[] keys = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash)); using (TripleDESCryptoServiceProvider TripDes = new TripleDESCryptoServiceProvider() { Key = keys, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }) { ICryptoTransform transform = TripDes.CreateEncryptor(); byte[] result = transform.TransformFinalBlock(data, 0, data.Length); var customerregister = new CustomerRegister { CustomerEmail = customerRegisterViewModel.CustomerEmail, CustomerPhone = customerRegisterViewModel.CustomerPhone, Password = Convert.ToBase64String(result, 0, result.Length) }; unitOfWork.CustomerregisterRepository.Insert(customerregister); unitOfWork.Save(); } } } //MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); //var utf8 = new UTF8Encoding(); //byte[] data = md5.ComputeHash(utf8.GetBytes(customerRegisterViewModel.Password)); // var customerregister = new CustomerRegister // { // CustomerEmail = customerRegisterViewModel.CustomerEmail, // CustomerPhone = customerRegisterViewModel.CustomerPhone, // Password = Convert.ToBase64String(data) // }; // unitOfWork.CustomerregisterRepository.Insert(customerregister); // unitOfWork.Save(); //} }
public IActionResult AddChannel(CustomerRegisterViewModel model) { var customer = _customerBusiness.AddChannel(model, ApplicationUserCurrent.AccountId); return(RedirectToAction("Register", new { idCustomer = customer.Id })); }
public async Task <ActionResult> RegisterArtistAgent(CustomerRegisterViewModel model) { if (ModelState.IsValid) { bool ajaxValidationResult = CaptchaControl.AjaxValidate (model.CaptchaId, model.CaptchaInput, model.InstanceId); if (ajaxValidationResult) { try { // Set customer details ArtistAgent artistAgent = new ArtistAgent() { CompanyName = model.CompanyName }; var user = new PaskolUser { RegisteredDate = DateTime.Now, UserName = model.Name, Email = model.Email, ArtistAgent = artistAgent, UserType = UserType.ArtistAgent, Status = UserStatus.Active }; // Create user var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { // assign user to role var roleResoult = await UserManager.AddToRoleAsync(UserManager.FindByName(model.Name).Id, UserType.ArtistAgent.ToString()); // Sign in await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // email to artist agent EmailService.RegisterArtistAgnt(model.Email, model.Name, model.Password); return(Json(new { suceeded = true, UserName = model.Name })); } AddErrors(result); } catch (Exception ex) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "ארעה שגיאה אנא פנה לתמיכה")); } } else { // handle not valid captcha _errors.Add(new KeyValuePair <string, string>("Captcha", "")); } } return(Json(new { suceeded = false, errors = _errors })); }
public async Task <IActionResult> Register(CustomerRegisterViewModel vm, IFormFile file) { if (ModelState.IsValid) { //user IdentityUser user = new IdentityUser(vm.UserName); //add to database IdentityResult result = await _userManagerService.CreateAsync(user, vm.Password); if (vm.Password != null) { vm.Password = vm.ConfirmPassword; } if (result.Succeeded) { //add a default role if (await _roleManagerService.FindByNameAsync("Customer") != null) { await _userManagerService.AddToRoleAsync(user, "Customer"); } //add default profile //get the user back to find the id user = await _userManagerService.FindByNameAsync(vm.UserName); Customer profile = new Customer { UserId = user.Id, FirstName = vm.FirstName, LastName = vm.LastName, Address = vm.Address, Email = vm.Email, Phone = vm.Mobile, ProfilePhoto = vm.ProfilePhoto }; //..file if (file != null) { //upload server path var uploadPath = Path.Combine(_environment.WebRootPath, "images"); //create subfolder Directory.CreateDirectory(Path.Combine(uploadPath, vm.UserName)); //get the file name string fileName = FileNameHelper.GetNameFormated(Path.GetFileName(file.FileName)); // stream the file to the srever using (var fileStream = new FileStream(Path.Combine(uploadPath, vm.UserName, fileName), FileMode.Create)) { await file.CopyToAsync(fileStream); } //add the file url to category profile.ProfilePhoto = vm.UserName + "/" + fileName; } _customerDataService.Create(profile); //go to home page return(RedirectToAction("Login", "Account")); } else { foreach (var item in result.Errors) { //show ModelState.AddModelError("", item.Description); } } } return(View(vm)); }
public JsonResult CustomerRegister(CustomerRegisterViewModel customerRegisterViewModel) { customerRegisterService.Register(customerRegisterViewModel); Session["cusId"] = customerRegisterViewModel.CustomerPhone; return(Json(new { success = customerRegisterViewModel.Errormessage })); }
public IActionResult DeleteProductCategory(CustomerRegisterViewModel model) { _customerBusiness.DeleteProductCategory(model, ApplicationUserCurrent.AccountId); return(RedirectToAction("Register", new { idCustomer = model.Id })); }