Beispiel #1
0
        public ActionResult UpdateAccountSettings(tb_employer_registration_data changed_employer_data)
        {
            db = new DinJobPortalEntities();

            tb_user existing_user_data;

            try
            {
                //tb_user user;
                existing_user_data = (tb_user)Session["user"];
                if (existing_user_data != null)
                {
                    if (existing_user_data.user_type == "employer")
                    {
                        var previous_email = existing_user_data.email;
                        existing_user_data       = db.tb_user.Where(tempuser => tempuser.id == existing_user_data.id).Include(tempuser => tempuser.tb_employer_registration_data).FirstOrDefault <tb_user>();
                        existing_user_data.email = changed_employer_data.email;
                        existing_user_data.tb_employer_registration_data.FirstOrDefault().email        = changed_employer_data.email;
                        existing_user_data.tb_employer_registration_data.FirstOrDefault().first_name   = changed_employer_data.first_name;
                        existing_user_data.tb_employer_registration_data.FirstOrDefault().last_name    = changed_employer_data.last_name;
                        existing_user_data.tb_employer_registration_data.FirstOrDefault().company_name = changed_employer_data.company_name;
                        existing_user_data.tb_employer_registration_data.FirstOrDefault().mobile       = changed_employer_data.mobile;
                        existing_user_data.tb_employer_registration_data.FirstOrDefault().cnic         = changed_employer_data.cnic;
                        if (ModelState.IsValid)
                        {
                            db.Entry(existing_user_data).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            Session["user"] = existing_user_data;
                            if (previous_email != existing_user_data.email)
                            {
                                Random  rnd      = new Random();
                                decimal randomNo = rnd.Next(10000000, 99999999);
                                objUtility = new UtilityMethods.Utility();
                                bool isEmailSent = objUtility.SendVerificationEmail(existing_user_data.email, randomNo);
                                if (isEmailSent)
                                {
                                    Session["user_email"]        = existing_user_data.email;
                                    Session["verification_code"] = randomNo;
                                    return(RedirectToAction("VerifyEmail", "User"));
                                }
                            }
                            return(RedirectToAction("AccountSetting"));
                        }
                        else
                        {
                            return(View("AccountSetting", existing_user_data));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                objUtility = new UtilityMethods.Utility();
                objUtility.SaveException_for_ExceptionLog(e);
                ViewBag.Exception = e.Message;
                return(RedirectToAction("DbError", "User", e));
            }
            return(View("AccountSetting"));
        }
Beispiel #2
0
        public ActionResult ValidateEmployeeSignUp(tb_user user, tb_employee_registration_data employee, string password_reenter, string fulltime, string parttime, string internship, string govt)
        {
            #region Employee Registration Validation
            try
            {
                string interests = fulltime + "," + parttime + "," + internship + "," + govt;


                employee.job_interest = interests;
                List <tb_employee_registration_data> emp = new List <tb_employee_registration_data>();
                emp.Add(employee);
                user.tb_employee_registration_data = emp;
                if (db.tb_user.Any(existing_User_Email => existing_User_Email.email == user.email))
                {
                    ModelState.AddModelError("email", "Email already exists");
                    return(View("MyAccount", user));
                }
                if (!string.IsNullOrEmpty(user.password))
                {
                    if (user.password != password_reenter)
                    {
                        ModelState.AddModelError("password", "Kindly Enter Same Password in both fields");
                    }
                    //if (user.password.Length < 6 || user.password.Length > 32)
                    //{
                    //    ModelState.AddModelError("password", "Kindly Enter Password between 6 and 32 sharacters");
                    //}
                }
                #region commented

                /*
                 * else
                 * {
                 *  ModelState.AddModelError("password", "Password is required");
                 * }
                 *
                 * if (string.IsNullOrEmpty(user.tb_employee_registration_data.First().first_name))
                 * {
                 *  ModelState.AddModelError("first_name", "First Name is required");
                 * }
                 * if (string.IsNullOrEmpty(user.tb_employee_registration_data.FirstOrDefault().last_name))
                 * {
                 *  ModelState.AddModelError("last_name", "Last Name is required");
                 * }
                 * if (string.IsNullOrEmpty(user.tb_employee_registration_data.FirstOrDefault().gender))
                 * {
                 *  ModelState.AddModelError("gender", "Gender is required");
                 * }
                 * if (string.IsNullOrEmpty(user.tb_employee_registration_data.FirstOrDefault().location))
                 * {
                 *  ModelState.AddModelError("location", "Location is required");
                 * }
                 * if (string.IsNullOrEmpty(user.tb_employee_registration_data.FirstOrDefault().job_title))
                 * {
                 *  ModelState.AddModelError("job_title", "Job Tilte is required");
                 * }
                 * if (string.IsNullOrEmpty(user.tb_employee_registration_data.FirstOrDefault().job_catagory_field))
                 * {
                 *  ModelState.AddModelError("job_catagory_field", "Catagory is required");
                 * }
                 * if (!string.IsNullOrEmpty(user.email))
                 * {
                 *  //string emailRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                 *  //                         @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                 *  //                            @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
                 *  //Regex re = new Regex(emailRegex);
                 *  //if (!re.IsMatch(user.email))
                 *  //{
                 *  //    ModelState.AddModelError("email", "Email is not valid");
                 *  //}
                 * }
                 * else
                 * {
                 *  ModelState.AddModelError("email", "Email is required");
                 * }*/
                #endregion

                if (ModelState.IsValid)
                {
                    try
                    {
                        string encPassword = encryption.encryptPassword(user.password);
                        user.password = encPassword;
                        db.tb_user.Add(user);
                        db.SaveChanges();
                        int     id       = user.id;
                        Random  rnd      = new Random();
                        decimal randomNo = rnd.Next(10000000, 99999999);
                        objUtility = new UtilityMethods.Utility();
                        bool isEmailSent = objUtility.SendVerificationEmail(user.email, randomNo);
                        if (isEmailSent)
                        {
                            Session["user_email"]        = user.email;
                            Session["verification_code"] = randomNo;
                            return(RedirectToAction("VerifyEmail"));
                        }
                    }
                    catch (Exception e)
                    {
                        objUtility = new UtilityMethods.Utility();
                        objUtility.SaveException_for_ExceptionLog(e);
                        ViewBag.Exception = e.Message;
                        return(View("DbError"));
                    }
                }
                return(View("MyAccount", user));
            }
            catch (Exception e)
            {
                //tb_exception ex = new tb_exception();
                //ex.date = System.DateTime.Now;
                //ex.exception_message = e.Message;
                //ex.exception_stack_trace = e.StackTrace;
                //db.tb_exception.Add(ex);
                objUtility = new UtilityMethods.Utility();
                objUtility.SaveException_for_ExceptionLog(e);
                ViewBag.Exception = e.Message;
                return(View("DbError"));
            }
            #endregion
        }
Beispiel #3
0
        public ActionResult ValidateEmployerSignUp(tb_user user, tb_employer_registration_data employer, string password_reenter) //*, string password_reenter, string mobileNo, string cnicNo*?/
        {
            #region Employer Registration Validation
            try{
                user.user_type = "employer";

                /*  var tempMobile = mobileNo.Split('-');
                 * employer.mobile = decimal.Parse(tempMobile[0] + tempMobile[1]);
                 * var tempCnic = cnicNo.Split('-');
                 * employer.cnic = decimal.Parse(tempCnic[0] + tempCnic[1] + tempCnic[2]);*/
                List <tb_employer_registration_data> emp = new List <tb_employer_registration_data>();
                emp.Add(employer);
                user.tb_employer_registration_data = emp;
                if (db.tb_user.Any(usr => usr.email == user.email))
                {
                    ModelState.AddModelError("email", "This email already exists");
                    return(View("MyAccount", user));
                }
                if (!string.IsNullOrEmpty(user.password))
                {
                    if (user.password != password_reenter)
                    {
                        ModelState.AddModelError("password", "Kindly Enter Same Password in both fields");
                    }
                    // if (user.password.Length < 6 || user.password.Length > 32)
                    //{
                    //  ModelState.AddModelError("password", "Kindly Enter Password between 6 and 32 sharacters");
                    //}
                }
                #region Commented

                /*
                 * else
                 * {
                 *  ModelState.AddModelError("password", "Password is required");
                 * }
                 *
                 * if (string.IsNullOrEmpty(user.tb_employer_registration_data.First().first_name))
                 * {
                 *  ModelState.AddModelError("first_name", "First Name is required");
                 * }
                 * if (string.IsNullOrEmpty(user.tb_employer_registration_data.FirstOrDefault().last_name))
                 * {
                 *  ModelState.AddModelError("last_name", "Last Name is required");
                 * }
                 * if (string.IsNullOrEmpty(user.tb_employer_registration_data.FirstOrDefault().company_name))
                 * {
                 *  ModelState.AddModelError("company_name", "Company name is required");
                 * }
                 * if (user.tb_employer_registration_data.FirstOrDefault().mobile.ToString().Length<9)
                 * {
                 *  ModelState.AddModelError("mobile", "Mobile is required and should be Valid");
                 * }
                 * if (user.tb_employer_registration_data.FirstOrDefault().cnic<12)
                 * {
                 *  ModelState.AddModelError("cnic", "CNIC is required");
                 * }
                 *
                 * if (!string.IsNullOrEmpty(user.email))
                 * {
                 *  string emailRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                 *                           @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                 *                              @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
                 *  Regex re = new Regex(emailRegex);
                 *  if (!re.IsMatch(user.email))
                 *  {
                 *      ModelState.AddModelError("email", "Email is not valid");
                 *  }
                 * }
                 * else
                 * {
                 *  ModelState.AddModelError("email", "Email is required");
                 * }*/
                #endregion
                if (ModelState.IsValid)
                {
                    try
                    {
                        PasswordEncryption enc         = new PasswordEncryption();
                        string             encPassword = enc.encryptPassword(user.password);
                        user.password = encPassword;
                        db.tb_user.Add(user);
                        db.SaveChanges();
                        int     id       = user.id;
                        Random  rnd      = new Random();
                        decimal randomNo = rnd.Next(10000000, 99999999);
                        objUtility = new UtilityMethods.Utility();
                        bool isEmailSent = objUtility.SendVerificationEmail(user.email, randomNo);
                        if (isEmailSent)
                        {
                            Session["user_email"]        = user.email;
                            Session["verification_code"] = randomNo;
                            return(RedirectToAction("VerifyEmail", "User"));
                        }
                    }
                    catch (Exception e)
                    {
                        objUtility = new UtilityMethods.Utility();
                        objUtility.SaveException_for_ExceptionLog(e);
                        ViewBag.Exception = e.Message;
                        return(View("DbError"));
                    }
                }
                return(View("MyAccount", user));
            }
            catch (Exception e)
            {
                //tb_exception ex = new tb_exception();
                //ex.date = System.DateTime.Now;
                //ex.exception_message = e.Message;
                //ex.exception_stack_trace = e.StackTrace;
                //db.tb_exception.Add(ex);
                objUtility = new UtilityMethods.Utility();
                objUtility.SaveException_for_ExceptionLog(e);
                ViewBag.Exception = e.Message;
                return(View("DbError"));
            }


            #endregion
            //return View("MyAccount");
        }
Beispiel #4
0
        public ActionResult MyAccount(string email, string password, string rememberme)
        {
            // userName = "******";
            string encPassword = encryption.encryptPassword(password);
            //  encPassword = "******";
            tb_user user_from_db_to_verify;

            try
            {
                user_from_db_to_verify = db.tb_user.Where(user => (user.email == email && user.password == encPassword)).FirstOrDefault <tb_user>();

                if (user_from_db_to_verify != null)
                {
                    if (user_from_db_to_verify.is_active == true && user_from_db_to_verify.is_verified == true)
                    {
                        user_from_db_to_verify.last_login      = System.DateTime.Now;
                        db.Entry(user_from_db_to_verify).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                        if (user_from_db_to_verify.user_type == "employee")
                        {
                            user_from_db_to_verify.tb_employee_registration_data.Add(db.tb_employee_registration_data.Where(employee => employee.user_id == user_from_db_to_verify.id).FirstOrDefault <tb_employee_registration_data>());
                        }
                        else if (user_from_db_to_verify.user_type == "employer")
                        {
                            user_from_db_to_verify.tb_employer_registration_data.Add(db.tb_employer_registration_data.Where(employer => employer.user_id == user_from_db_to_verify.id).FirstOrDefault <tb_employer_registration_data>());
                        }
                        if (rememberme != null)
                        {
                            ///cookies
                        }
                        Session["user"] = user_from_db_to_verify;
                        Session["type"] = user_from_db_to_verify.user_type;
                        return(RedirectToAction("Home", "User"));
                    }
                    else if (user_from_db_to_verify.is_verified == false)
                    {
                        if (Session["verification_code"] == null)
                        {
                            Random  rnd      = new Random();
                            decimal randomNo = rnd.Next(10000000, 99999999);
                            objUtility = new UtilityMethods.Utility();
                            bool isEmailSent = objUtility.SendVerificationEmail(email, randomNo);
                            if (isEmailSent)
                            {
                                Session["user_email"]        = email;
                                Session["verification_code"] = randomNo;
                                //return RedirectToAction("VerifyEmail");
                            }
                        }
                    }
                    ViewBag.SuccessMessage = "You have not verified your account. Check your email and verify";
                    return(View("VerifyEmail"));
                }
                ViewBag.ErrorLogin = "******";
                return(View("MyAccount"));
            }
            catch (Exception e)
            {
                objUtility = new UtilityMethods.Utility();
                objUtility.SaveException_for_ExceptionLog(e);
                ViewBag.Exception = e.Message;
                return(View("DbError"));
            }
            //return View("MyAccount");
        }