Ejemplo n.º 1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var newUser = new User()
                {
                    CreatedOn  = DateTime.Now,
                    ModifiedOn = DateTime.Now,
                    IsActive   = true,
                    IsApproved = false,
                    IsDeleted  = false,
                    Password   = model.Password,
                    UserName   = model.Email,
                    FirstName  = model.FirstName,
                    LastName   = model.LastName,
                    AcceptTermAndConditions = model.AcceptTermAndConditions,
                    AddressLine1            = "",
                    AddressLine2            = "",
                    CityId           = 0,
                    CoverPictureId   = model.CoverPictureId,
                    Email            = model.Email,
                    MiddleName       = "",
                    ProfilePictureId = model.ProfilePictureId,
                    UserGuid         = Guid.NewGuid(),
                    UserId           = 1
                };

                var defaultRole = _roleService.GetRoleByName("General");
                if (defaultRole != null)
                {
                    newUser.Roles.Add(defaultRole);
                }

                _userService.Insert(newUser);

                var verificationLink = Url.ActionEnc("VerificationUrl", "EmailVerification", new { email = newUser.Email, code = newUser.UserGuid });
                // Send Notification To The Admin
                var setting = _settingService.GetSettingByKey("FromEmail");
                if (!String.IsNullOrEmpty(setting.Value))
                {
                    _emailService.SendUserEmailVerificationMessage(newUser, verificationLink);
                }

                SuccessNotification("You Are Registered Successfully. Please Check Your Inbox For Verification.");
                return(RedirectToAction(nameof(HomeController.Index), "Home"));
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult ForgotPassword(ForgotPasswordModel model)
        {
            if (string.IsNullOrEmpty(model.Emailaddress))
            {
                model.Success = false;
                model.Message = "Please enter a valid email address.";
                return(View(model));
            }

            var user = _userService.GetUserByEmail(model.Emailaddress);

            if (user != null)
            {
                // Get Forgot Password Template
                var configSetting = _settingService.GetSettingByKey("ForgotTemplate");
                if (configSetting != null)
                {
                    var templateName = configSetting.Value;
                    var template     = _templateService.GetTemplateByName(templateName);
                    if (template != null)
                    {
                        var _lstTokens = template.Tokens.ToList();
                        _templateService.AddUserTokens(_lstTokens, user);

                        string passwordLink = Url.ActionEnc("ForgotPassword", "ResetPassword", new { @email = user.Email, @code = user.UserGuid.ToString(), @isreset = false });
                        _emailService.SendUserForgotPasswordMessage(user, passwordLink);
                        SuccessNotification("A password change request has been sent on your email address. Please follow instructions written in the mail.");
                    }
                }
                else
                {
                    ErrorNotification("Configuration Template setting not available, contact administrator.");
                }
            }

            return(RedirectToAction("Login"));
        }