Пример #1
0
        public ActionResult ChangePassword(ChangeOldPasswordViewModel suvm)
        {
            var    PwdHashing   = new PasswordHashing();
            string emailAddress = Session["Username"].ToString();
            var    chkUser      = (from l in db.Users
                                   where l.UserEmail == emailAddress
                                   select l).FirstOrDefault();

            if (chkUser != null)
            {
                try
                {
                    var decriptPwd = PwdHashing.Encrypt(suvm.UserPassword);
                    chkUser.UserPassword        = decriptPwd;
                    chkUser.UserConfirmPassword = decriptPwd;
                    db.SaveChanges();
                    ViewBag.DisplayMessage = "success";
                    ModelState.AddModelError("", "Your password reset was successful!");
                }
                catch (Exception)
                {
                    ViewBag.DisplayMessage = "Info";
                    ModelState.AddModelError("", "password reset was not successful, please try again!");
                }
            }
            else
            {
                ViewBag.DisplayMessage = "Info";
                ModelState.AddModelError("", "Email address does not exist!");
            }
            return(View());
        }
Пример #2
0
        public ActionResult ForgetSecurityAnswer(string emailAddress)
        {
            var chkUser = (from l in db.Users
                           where l.UserEmail == emailAddress
                           select l).FirstOrDefault();

            if (chkUser != null)
            {
                StringBuilder buffer;

                try
                {
                    String pin = System.Guid.NewGuid().ToString();
                    buffer        = new StringBuilder(pin);
                    buffer.Length = 8;
                    var newSecurityAnswer = buffer.ToString().ToUpper();

                    var decriptPwd = PwdHashing.Encrypt(newSecurityAnswer);
                    chkUser.SecurityAnswer = decriptPwd;
                    //chkUser.UserConfirmPassword = decriptPwd;
                    db.SaveChanges();
                    ProcessEmail(newSecurityAnswer, chkUser.UserEmail, chkUser.UserFirstName, chkUser.UserLastName);
                    ViewBag.DisplayMessage = "success";
                    ModelState.AddModelError("", "Security answer reset was successful, a new security answer has been sent to your email address!");
                }
                catch (Exception)
                {
                    ViewBag.DisplayMessage = "Info";
                    ModelState.AddModelError("", "Security answer was not successful, please contact the admin!");
                }
            }
            else
            {
                ViewBag.DisplayMessage = "Info";
                ModelState.AddModelError("", "Email address does not exist!");
            }
            return(View());
        }
Пример #3
0
        public ActionResult SignUp([Bind(Include = "UserID,UserFirstName,UserLastName,UserAddress1,UserAddress2,CountryID,UserStateList,UserCity,UserEmail, " +
                                                   " UserPassword,UserConfirmPassword,SecurityQuestionIDList,SecurityAnswer,UserPhone,CreatedOn,Gender,IsDeleted,UserRole")] SignUpViewModel suvm, string lga, string State, string terms, string txtState, string txtCity)
        {
            try
            {
                ViewBag.StateId = new SelectList(db.States, "StateID", "StateName");
                string termsAndCondition = (terms == "yes") ? "Agreed" : "Not Agreed";

                //var state = (txtState != "") ? txtState : State;
                string state = "";
                var    lga3  = (txtCity != "") ? txtCity : lga;

                if (txtState != "")
                {
                    state = txtState;
                }
                else
                {
                    int enteredStateID = Convert.ToInt32(State);
                    var stateID        = (from st in db.States where (st.StateID == enteredStateID) select st).FirstOrDefault();
                    state = stateID.StateName;
                }

                var activationID = Guid.NewGuid();
                var encriptPwd   = new PasswordHashing();
                if (termsAndCondition == "Agreed")
                {
                    // string sexGender = suvm.Gender;
                    int sqs             = suvm.SecurityQuestionIDList.Value;
                    var itemCollections = new User
                    {
                        UserLastName        = suvm.UserLastName,
                        UserFirstName       = suvm.UserFirstName,
                        UserAddress1        = suvm.UserAddress1,
                        UserAddress2        = suvm.UserAddress2,
                        UserState           = state.ToString(),
                        UserCity            = lga3,
                        UserEmail           = suvm.UserEmail,
                        UserPassword        = encriptPwd.Encrypt(suvm.UserPassword),
                        UserConfirmPassword = encriptPwd.Encrypt(suvm.UserConfirmPassword),
                        SecurityQuestionID  = Convert.ToInt16(suvm.SecurityQuestionIDList),
                        SecurityAnswer      = encriptPwd.Encrypt(suvm.SecurityAnswer),
                        UserPhone           = suvm.UserPhone,
                        CreatedOn           = DateTime.Now,
                        GenderID            = suvm.Gender.Value,
                        IsDeleted           = false,
                        CountryID           = suvm.CountryID,
                        UserRole            = suvm.UserRole,
                        IsActivated         = false,
                        ActivationID        = activationID,
                    };

                    var uir = new UsersInRole
                    {
                        UserID = suvm.UserID,
                        RoleID = Convert.ToInt32(suvm.UserRole)
                    };
                    LoadDropDownList();
                    var chkExistingEmail = (from l in db.Users
                                            where l.UserEmail == suvm.UserEmail
                                            select l).FirstOrDefault();
                    if (chkExistingEmail == null)
                    {
                        try
                        {
                            string newActivationID = activationID.ToString();
                            itemCollections.UsersInRoles.Add(uir);
                            db.Users.Add(itemCollections);
                            db.SaveChanges();
                            EmailNotification.ProcessEmailForAccountActivation(suvm.UserEmail, suvm.UserFirstName, suvm.UserLastName, newActivationID, suvm.UserEmail);
                            LoadDropDownList();
                            ViewBag.DisplayMessage = "success";
                            ModelState.AddModelError("", "Record Saved Successfully, an activation link has been sent to your inbox, kindly activate your account so you will be able to login!");
                        }
                        catch (Exception ex)
                        {
                            ViewBag.DisplayMessage = "Info";
                            ModelState.AddModelError("", ex.Message);
                        }
                    }
                    else
                    {
                        ViewBag.DisplayMessage = "Info";
                        ModelState.AddModelError("", "This email address has already been used, enter a different email address!");
                        LoadDropDownList();
                        return(View());
                    }
                }


                if (termsAndCondition == "Not Agreed")
                {
                    ViewBag.DisplayMessage = "Info";
                    ModelState.AddModelError("", "You must agree to our terms and conditions before submitting the form");

                    LoadDropDownList();
                    return(View());
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View());
            }
            return(View());
        }