public async Task<IActionResult> Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Errors.AddModelStateErrors(ModelState);
                return View(model);
            }

            var user = new CustomUser(model.Email);

            var result = await userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                var signInResult = await signInManager.PasswordSignInAsync(user.UserName, model.Password, false, false);

                if (signInResult.Succeeded)
                {
                    return RedirectToAction("Index", "Home");
                }

                model.Errors.Add("Registration was successful however sign-in failed. Please try to sign in again");
            }
            else
            {
                foreach (var error in result.Errors)
                {
                    model.Errors.Add(error.Description);
                }
            }
            return View(model);
        }
Пример #2
0
        public ViewResult Register(ViewModels.RegisterViewModel registerViewModel)
        {
            if (ModelState.IsValid)
            {
                if (!DatabaseContext.Users.Any(current => current.EmailAddress == registerViewModel.EmailAddress.Trim().ToLower()))
                {
                    Models.User user = new Models.User
                    {
                        RoleId       = 1,
                        Username     = registerViewModel.Username,
                        EmailAddress = registerViewModel.EmailAddress.Trim().ToLower(),
                        Password     = registerViewModel.Password,
                        ActiveCode   = System.Guid.NewGuid().ToString(),
                        IsActive     = true,
                        RegisterDate = System.DateTime.Now,
                    };

                    DatabaseContext.Users.Add(user);
                    DatabaseContext.SaveChanges();

                    #region Send Active EmailAddress
                    string body = PartialToStringClass.RenderPartialView("ManageEmails", "_ActivationEmailPartialView", user);
                    SendEmail.Send(user.EmailAddress, "ایمیل فعالسازی", body);
                    #endregion

                    return(View("SuccessRegister", user));
                }
                else
                {
                    ModelState.AddModelError(registerViewModel.EmailAddress, "ایمیل وارد شده تکراری می باشد");
                }
            }
            return(View(registerViewModel));
        }
Пример #3
0
 public ActionResult Register(RegisterViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         CryptoHelper cryptoHelper = new CryptoHelper();
         var agency = viewModel.Agenzia;
         agency.Password = cryptoHelper.CryptPassword(agency.Password);
         var ar = new AgenziaRepository();
         ar.Save(agency);
         Session.Login(agency);
         if (agency.IsTourOperator)
             return RedirectToAction("TourOperatorDashboard", "Dashboard", new { id = agency.Id });
         return RedirectToAction("AgenziaDashboard", "Dashboard", new { id = agency.Id });
     }
     else return View(viewModel);
 }
Пример #4
0
 public ActionResult Login(string password, string email)
 {
     CryptoHelper cryptoHelper = new CryptoHelper();
     var ar = new AgenziaRepository();
     var agency = ar.GetByEmail(email);
     if (agency == null)
         return View("Register");
     var cryptedPassword = cryptoHelper.CryptPassword(password);
     if (cryptedPassword.Equals(agency.Password))
     {
         Session.Login(agency);
         if (agency.IsTourOperator)
             return RedirectToAction("TourOperatorDashboard", "Dashboard", new { id = agency.Id });
         return RedirectToAction("AgenziaDashboard", "Dashboard", new { id = agency.Id });
     }
     var viewModel = new RegisterViewModel();
     return View("Register", viewModel);
 }
Пример #5
0
        public async Task <IActionResult> Register(ViewModels.RegisterViewModel vMRegister)
        {
            if (ModelState.IsValid)
            {
                var user = new User {
                    UserName = vMRegister.Mobile
                };
                var result = await _userManager.CreateAsync(user, vMRegister.Password);

                var error = result.Errors.Where(C => C.Code == "DuplicateUserName").FirstOrDefault();
                if (error != null)
                {
                    ViewData["DuplicateUserName"] = "******";
                }
                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, false);

                    return(RedirectToAction("Login"));
                }
            }
            return(View());
        }
Пример #6
0
 public ActionResult ResetPassword(string email)
 {
     var ar = new AgenziaRepository();
     var agency = ar.GetByEmail(email);
     if (agency != null)
     {
         CryptoHelper cryptoHelper = new CryptoHelper();
         var random = new Random();
         var password = random.Next().ToString();
         agency.Password = cryptoHelper.CryptPassword(password);
         ar.Save(agency);
         var mailerHelper = new MailerHelper();
         var text = string.Format("Gentile {0} la tua nuova password di Parti Comodo è: {1}", agency.Nome, password);
         mailerHelper.SendMail(email, text);
     }
     var viewModel = new RegisterViewModel();
     return View("Register", viewModel);
 }
Пример #7
0
 public ActionResult Register()
 {
     var viewModel = new RegisterViewModel();
     return View(viewModel);
 }
Пример #8
0
        private void Register()
        {
            if (!String.IsNullOrEmpty(UserEmail))
            {
                try
                {
                    LoginUser.GetUser_ByEmail();
                    ErrorText = "User already exists";
                    ErrorActive = true;
                    LoginUser = new User();
                }
                catch (ArgumentNullException ex)
                {
                    if (ex.Message.Equals("User does not exists\r\nParameter name: Get User info fail"))
                    {
                        ViewWindow RegisterWindow;
                        BaseViewModel RegisterWindow_ViewModel;

                        RegisterWindow = new ViewWindow();
                        RegisterWindow_ViewModel = new RegisterViewModel(LoginUser);
                        ((RegisterViewModel)RegisterWindow_ViewModel).OnUserRegistrated += Registradet;
                        RegisterWindow_ViewModel.ShowInWindow(RegisterWindow);
                    }
                    else
                    {
                        ErrorText = ex.Message;
                        ErrorActive = true;
                    }
                }
                catch (Exception ex)
                {
                    ErrorText = ex.Message;
                    ErrorActive = true;
                }
            }
            else
            {
                ErrorText = "Missing email";
                ErrorActive = true;
            }
        }
Пример #9
0
        public void Register(RegisterViewModel viewmodel)
        {
            var user = Mapper.Map<RegisterViewModel, User>(viewmodel);

            user.Id = Guid.NewGuid();
            user.Role = "user";
            user.Salt = CreateSalt();
            user.Password = Convert.ToBase64String(GetHash(user.Password, user.Salt));

            user.StartDate = DateTime.Now;
            user.SubscriptionEndDate = DateTime.Now.Date.AddMonths(user.SubscriptionPeriod);

            _unitOfWork.Users.Add(user);
            _unitOfWork.Commit();
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = new User { UserName = model.Username, Email = model.Email };
                var result = await this.UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await this.SignInManager.SignInAsync(user, false, false);
                    
                    // For more information on how to enable account confirmation and password reset please visit http://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>");

                    return this.RedirectToAction("Index", "Home");
                }
                this.AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return this.View(model);
        }
Пример #11
0
        public HttpResponseMessage Register(RegisterViewModel viewmodel)
        {
            if (ModelState.IsValid)
            {
                if (_userService.CheckIfEmailIsUnique(viewmodel.Email))
                {
                    _userService.Register(viewmodel);
                    return new HttpResponseMessage(HttpStatusCode.OK);
                }
            }

            return new HttpResponseMessage(HttpStatusCode.BadRequest);
        }
Пример #12
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = new User
                {
                    UserName = model.Email,
                    Email = model.Email
                };

                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await this.SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    return this.RedirectToAction("Index", "Home");
                }

                this.AddErrors(result);
            }
            
            return this.View(model);
        }