Example #1
0
        public ActionResult ForgotPassword(string Email)
        {
            bool status = false;

            using (TeacherRegsEntities teacherReg = new TeacherRegsEntities())
            {
                var account = teacherReg.TeacherLogins.Where(a => a.Email == Email).FirstOrDefault();
                if (account != null)
                {
                    //Send email for reset password
                    string resetCode = Guid.NewGuid().ToString();
                    SendVerificationLinkEmail(account.Email, resetCode, "ResetPassword");
                    account.ResetPasswordCode = resetCode;

                    //Avoid confirm password not match issue, as we had added a confirm password property
                    teacherReg.Configuration.ValidateOnSaveEnabled = false;
                    teacherReg.SaveChanges();
                    ViewBag.Message = "Reset password link has been sent to your email id";
                    ModelState.Clear();
                }
                else
                {
                    ViewBag.ErrorMessage = "Sorry! account not found";
                }
            }
            return(View());
        }
Example #2
0
        public ActionResult Register([Bind(Exclude = "IsEmailVerified,ActivationCode")] TeacherLogin teacherLogin)
        {
            bool   Status  = false;
            string message = "";

            if (ModelState.IsValid)
            {
                // Email is already Exist
                var isExist = IsEmailExist(teacherLogin.Email);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(teacherLogin));
                }

                // Generate Activation Code
                teacherLogin.ActivationCode = Guid.NewGuid();

                // Password Hashing
                teacherLogin.Password        = Crypto.Hash(teacherLogin.Password);
                teacherLogin.ConfirmPassword = Crypto.Hash(teacherLogin.ConfirmPassword);

                teacherLogin.IsEmailVerified = false;

                // Save to Database
                using (TeacherRegsEntities teacherReg = new TeacherRegsEntities())
                {
                    Teachers teacher = new Teachers();
                    teacher.Id = teacherLogin.Id;
                    if (teacher.checkId())
                    {
                        teacher.Initial = teacherLogin.Initial;
                        teacher.Registration();
                        teacherReg.TeacherLogins.Add(teacherLogin);
                        teacherReg.SaveChanges();

                        // Send Email to User
                        SendVerificationLinkEmail(teacherLogin.Email, teacherLogin.ActivationCode.ToString());
                        message = "Registration successfully done. Account activation link " +
                                  " has been sent to your email id:" + teacherLogin.Email;
                        Status = true;
                    }
                    else
                    {
                        message = "Invalid id";
                    }
                }
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View());
        }
Example #3
0
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (TeacherRegsEntities teacherReg = new TeacherRegsEntities())
            {
                teacherReg.Configuration.ValidateOnSaveEnabled = false; // This line I have added here to avoid
                // Confirm password does not match issue on save changes
                var v = teacherReg.TeacherLogins.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    teacherReg.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }
Example #4
0
 public ActionResult ResetPassword(ResetPassword reset)
 {
     if (ModelState.IsValid)
     {
         using (TeacherRegsEntities teacherReg = new TeacherRegsEntities())
         {
             var user = teacherReg.TeacherLogins.Where(a => a.ResetPasswordCode == reset.ResetCode).FirstOrDefault();
             if (user != null)
             {
                 user.Password          = Crypto.Hash(reset.NewPassword);
                 user.ResetPasswordCode = "";
                 teacherReg.Configuration.ValidateOnSaveEnabled = false;
                 teacherReg.SaveChanges();
                 ViewBag.message = "New password updated successfully";
             }
         }
         ModelState.Clear();
     }
     else
     {
         ViewBag.Errormessage = "Something invalid!";
     }
     return(View(reset));
 }