public ActionResult SignUp(User user) { if (this.Session["CaptchaImageText"].ToString() == user.SecurityCode) { string newSalt = PasswordEncryption.RandomString(); user.Password = PasswordEncryption.encryptPassword(user.Password, newSalt); user.Email = user.NewEmail; user.RoleId = 1; user.Status = true; user.step_status = 0; UserAccess ua = new UserAccess(); if (ua.InsertUser(user) >= 1) { //ViewBag.SuccessMsg = "Your profile Successfully created."; TempData["status"] = "success"; //If succeed update step table to step2 StepAccess sa = new StepAccess(); //if (sa.updateStepNumberByUserId(ua.getUserId(user.Email), 1)) return(RedirectToAction("UserLogin", "Login")); } TempData["status"] = "fail"; //ViewBag.ErrorMsg = "Failed to Sign up try again!"; } else { TempData["status"] = "captchaFail"; //ViewBag.ErrorMsg = "Entered Security Code is Not Correct!"; TempData["ErrorModel"] = user; } //return View(); return(RedirectToAction("SignUp")); }
public ActionResult CreateFirstSuperUser(User user) { //user.Password = PasswordEncryption.encryptPassword(user.Password); string newSalt = PasswordEncryption.RandomString(); user.Password = PasswordEncryption.encryptPassword(user.Password, newSalt); user.Email = user.NewEmail; TempData["User"] = user; return(RedirectToAction("Setup", "SetupCompany", new { id = 0, type = "CompanyEmployee" })); }
/* * * Frontend page: Reset Password page * Title: Update Password * Designed: Irfan Mam * User story: * Developed: Irfan MAM * Date created: 1/17/2016 * */ public bool resetPassword(int userId, ResetPassword resetPasswordModel) { DataHandler dataHandler = new DataHandler(); string newSalt = PasswordEncryption.RandomString(); resetPasswordModel.Password = PasswordEncryption.encryptPassword(resetPasswordModel.Password, newSalt); List <object[]> paramertList = new List <object[]>(); paramertList.Add(new object[] { "@user_id", userId }); paramertList.Add(new object[] { "@password", resetPasswordModel.Password }); try { return(dataHandler.ExecuteSQLWithReturnVal("spUpdatePassword", paramertList) > 0 ? true : false); } catch (Exception ex) { throw ex; } }
public ActionResult UserLogin(UserLogin user) { try { //string ip = Request.UserHostAddress; DataSet dsUser = new DataSet(); var login = new LoginAccess(); var step = new StepAccess(); User userData = new User(); userData.UserName = user.userName; //pass user name to database and get user details dsUser = login.CheckUserLogin(userData); if (dsUser.Tables[0].Rows.Count > 0) { userData.UserId = int.Parse(dsUser.Tables[0].Rows[0]["user_id"].ToString()); userData.UserName = dsUser.Tables[0].Rows[0]["user_name"].ToString(); userData.Password = dsUser.Tables[0].Rows[0]["password"].ToString(); userData.RoleId = int.Parse(dsUser.Tables[0].Rows[0]["role_id"].ToString()); if (userData.RoleId == 4) { DataSet dsDelearCompany = new DataSet(); dsDelearCompany = login.GetDealerUserCompanyBranch(userData.UserId); if (dsDelearCompany.Tables[0].Rows[0]["company_id"].ToString() != "") { userData.Company_Id = int.Parse(dsDelearCompany.Tables[0].Rows[0]["company_id"].ToString()); userData.CompanyName = dsDelearCompany.Tables[0].Rows[0]["company_name"].ToString(); } if (dsDelearCompany.Tables[0].Rows[0]["branch_id"].ToString() != "") { userData.BranchId = int.Parse(dsDelearCompany.Tables[0].Rows[0]["branch_id"].ToString()); userData.BranchName = dsDelearCompany.Tables[0].Rows[0]["branch_name"].ToString(); } } else { userData.BranchId = int.Parse(dsUser.Tables[0].Rows[0]["branch_id"].ToString()); userData.BranchName = dsUser.Tables[0].Rows[0]["branch_name"].ToString(); if (dsUser.Tables[0].Rows[0]["company_id"].ToString() != "") { userData.Company_Id = int.Parse(dsUser.Tables[0].Rows[0]["company_id"].ToString()); userData.CompanyType = int.Parse(dsUser.Tables[0].Rows[0]["company_type"].ToString()); userData.CompanyCode = dsUser.Tables[0].Rows[0]["company_code"].ToString(); } else { userData.Company_Id = 0; } userData.CompanyName = dsUser.Tables[0].Rows[0]["company_name"].ToString(); } userData.step_status = int.Parse(dsUser.Tables[0].Rows[0]["step_status"].ToString()); //To compair Database password and user enter password string passwordFromDB = userData.Password; char[] delimiter = { ':' }; string[] split = passwordFromDB.Split(delimiter); var checkCharHave = passwordFromDB.ToLowerInvariant().Contains(':'); if (passwordFromDB == null || (checkCharHave == false)) { Log log = new Log(userData.UserId, userData.Company_Id, userData.BranchId, 0, "User Login", "User : "******" was unable to login, Entered password did not match", DateTime.Now); int islog = (new LogAccess()).InsertLog(log); return(RedirectToAction("UserLogin", "Login", new { lbl = "Incorrect Username & Password combination. Please confirm entry and resubmit." })); } string passwordEncripted = PasswordEncryption.encryptPassword(user.password, split[1]); if (string.Compare(passwordEncripted, passwordFromDB) == 0) { //user object pass to session Session["AuthenticatedUser"] = userData; // Does not complete atleast one cycle if (userData.step_status == 0) { if (userData.RoleId == 3) { Log log = new Log(userData.UserId, userData.Company_Id, userData.BranchId, 0, "User Login", "User : "******" was unable to login", DateTime.Now); int islog = (new LogAccess()).InsertLog(log); return(RedirectToAction("UserLogin", "Login", new { lbl = "Company setup process is on going please contact admin." })); } else { Log log = new Log(userData.UserId, userData.Company_Id, userData.BranchId, 0, "User Login", "User : "******" has logged successfully", DateTime.Now); int islog = (new LogAccess()).InsertLog(log); if (userData.Company_Id == 0) { Session["companyStep"] = 1; return(RedirectToAction("Index", "SetupProcess")); } else if (userData.Company_Id > 0) { if (userData.RoleId == 1) { DataSet dsStepNo = new DataSet(); dsStepNo = step.checkSuperAdminLoginWhileCompanySetup(userData); if (dsStepNo.Tables[0].Rows.Count > 0) { Session["companyStep"] = int.Parse(dsStepNo.Tables[0].Rows[0]["step_number"].ToString()); return(RedirectToAction("Index", "SetupProcess")); } else { LoanSetupStep loanStep = new LoanSetupStep(); DataSet dsLoanStepNo = new DataSet(); dsLoanStepNo = step.checkUserLoginWhileLoanSetup(userData); if (dsLoanStepNo.Tables[0].Rows.Count > 0) { loanStep.CompanyId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["company_id"].ToString()); loanStep.BranchId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["branch_id"].ToString()); loanStep.stepId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["step_number"].ToString()); loanStep.nonRegisteredBranchId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["non_registered_branch_id"].ToString()); if (dsLoanStepNo.Tables[0].Rows[0]["loan_id"].ToString() != "") { loanStep.loanId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["loan_id"].ToString()); } else { loanStep.loanId = 0; } Session["loanStep"] = loanStep; if (userData.RoleId == 1) { return(RedirectToAction("Step" + (loanStep.stepId + 5), "SetupProcess")); } } } } else { //if step table has record pass(company id and branch id) DataSet dsStepNo = new DataSet(); dsStepNo = step.checkUserLoginWhileCompanySetup(userData); if (dsStepNo.Tables[0].Rows.Count > 0) { Session["companyStep"] = int.Parse(dsStepNo.Tables[0].Rows[0]["step_number"].ToString()); return(RedirectToAction("Index", "SetupProcess")); } else { //No Step recor in relavent Company and branch LoanSetupStep loanStep = new LoanSetupStep(); DataSet dsLoanStepNo = new DataSet(); dsLoanStepNo = step.checkUserLoginWhileLoanSetup(userData); if (dsLoanStepNo.Tables[0].Rows.Count > 0) { loanStep.CompanyId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["company_id"].ToString()); loanStep.BranchId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["branch_id"].ToString()); loanStep.stepId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["step_number"].ToString()); loanStep.nonRegisteredBranchId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["non_registered_branch_id"].ToString()); if (dsLoanStepNo.Tables[0].Rows[0]["loan_id"].ToString() != "") { loanStep.loanId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["loan_id"].ToString()); } else { loanStep.loanId = 0; } Session["loanStep"] = loanStep; return(RedirectToAction("Step" + (loanStep.stepId + 5), "SetupProcess")); } } } } } } // Complete cycle and no start new cycle else if (userData.step_status == 1 || userData.step_status == 2) { //delete just added unit if exists UnitAccess ua = new UnitAccess(); ua.DeleteJustAddedUnits(userData.UserId); //insert log Log log = new Log(userData.UserId, userData.Company_Id, userData.BranchId, 0, "User Login", "User : "******" has logged successfully", DateTime.Now); int islog = (new LogAccess()).InsertLog(log); return(RedirectToAction("UserDetails", "UserManagement")); } // atleast one cycle complete and Start new cycle //else if (userData.step_status == 2) //{ // //delete just added unit if exists // UnitAccess ua = new UnitAccess(); // ua.DeleteJustAddedUnits(userData.UserId); // //insert log // Log log = new Log(userData.UserId, userData.Company_Id, userData.BranchId, 0, "User Login", "User : "******" has logged successfully", DateTime.Now); // int islog = (new LogAccess()).InsertLog(log); // if (userData.RoleId == 1) // { // DataSet dsStepNo = new DataSet(); // dsStepNo = step.checkSuperAdminLoginWhileCompanySetup(userData); // if (dsStepNo.Tables[0].Rows.Count > 0) // { // Session["companyStep"] = int.Parse(dsStepNo.Tables[0].Rows[0]["step_number"].ToString()); // Session["isNotCompleteStep"] = 1; // //return RedirectToAction("Index", "SetupProcess"); // return RedirectToAction("UserLogin", "Login"); // } // else // { // LoanSetupStep loanStep = new LoanSetupStep(); // DataSet dsLoanStepNo = new DataSet(); // dsLoanStepNo = step.checkUserLoginWhileLoanSetup(userData); // if (dsLoanStepNo.Tables[0].Rows.Count > 0) // { // loanStep.CompanyId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["company_id"].ToString()); // loanStep.BranchId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["branch_id"].ToString()); // loanStep.stepId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["step_number"].ToString()); // loanStep.nonRegisteredBranchId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["non_registered_branch_id"].ToString()); // if (dsLoanStepNo.Tables[0].Rows[0]["loan_id"].ToString() != "") // { // loanStep.loanId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["loan_id"].ToString()); // } // else // { // loanStep.loanId = 0; // } // Session["isNotCompleteStep"] = 1; // Session["loanStep"] = loanStep; // if (userData.RoleId == 1) // { // //return RedirectToAction("Step" + (loanStep.stepId + 5), "SetupProcess"); // return RedirectToAction("UserLogin", "Login"); // } // } // } // } // else // { // //if step table has record pass(company id and branch id) // DataSet dsStepNo = new DataSet(); // dsStepNo = step.checkUserLoginWhileCompanySetup(userData); // if (dsStepNo.Tables[0].Rows.Count > 0) // { // Session["isNotCompleteStep"] = 1; // Session["companyStep"] = int.Parse(dsStepNo.Tables[0].Rows[0]["step_number"].ToString()); // return RedirectToAction("UserLogin", "Login"); // } // else // { // //No Step recor in relavent Company and branch // LoanSetupStep loanStep = new LoanSetupStep(); // DataSet dsLoanStepNo = new DataSet(); // dsLoanStepNo = step.checkUserLoginWhileLoanSetup(userData); // if (dsLoanStepNo.Tables[0].Rows.Count > 0) // { // loanStep.CompanyId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["company_id"].ToString()); // loanStep.BranchId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["branch_id"].ToString()); // loanStep.stepId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["step_number"].ToString()); // loanStep.nonRegisteredBranchId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["non_registered_branch_id"].ToString()); // if (dsLoanStepNo.Tables[0].Rows[0]["loan_id"].ToString() != "") // { // loanStep.loanId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["loan_id"].ToString()); // } // else // { // loanStep.loanId = 0; // } // Session["isNotCompleteStep"] = 1; // Session["loanStep"] = loanStep; // //return RedirectToAction("Step" + (loanStep.stepId + 5), "SetupProcess"); // return RedirectToAction("UserLogin", "Login"); // } // //if SA stepstatus 2 and no records in loan setup and companysetup // else // { // return RedirectToAction("UserDetails", "Usermanagement"); // } // } // } //} else { //insert log Log log = new Log(userData.UserId, userData.Company_Id, userData.BranchId, 0, "User Login", "User : "******" was unable to login", DateTime.Now); int islog = (new LogAccess()).InsertLog(log); return(RedirectToAction("UserLogin", "Login", new { lbl = "Company setup process is on going please contact admin." })); } // //check Company setup process // //Check SuperAdmin // //company ID null or 0 then redirect to step process 1 // if (userData.Company_Id == 0) // { // Session["companyStep"] = 1; // return RedirectToAction("Index", "SetupProcess"); // } // else if (userData.Company_Id > 0) // { // //check branch count more than one and // if (userData.RoleId == 1) // { // //check branch count in view and step table row count // //IF more than branch count and has step record ask question // DataSet dsStepNo = new DataSet(); // dsStepNo = step.checkSuperAdminLoginWhileCompanySetup(userData); // if (dsStepNo.Tables[0].Rows.Count > 0) // { // int bcount = 0; // if (dsStepNo.Tables[0].Rows[0]["branchCount"].ToString() != "") // { // bcount = int.Parse(dsStepNo.Tables[0].Rows[0]["branchCount"].ToString()); // } // int scount = 0; // if (dsStepNo.Tables[0].Rows[0]["stepCount"].ToString() != "") // { // scount = int.Parse(dsStepNo.Tables[0].Rows[0]["stepCount"].ToString()); // } // if (bcount <= scount) // { // Session["companyStep"] = int.Parse(dsStepNo.Tables[0].Rows[0]["step_number"].ToString()); // return RedirectToAction("Index", "SetupProcess"); // } // else // { // //message: Not complete Step, Do you want to complete it. // Session["isNotCompleteStep"] = 1; // Session["companyStep"] = int.Parse(dsStepNo.Tables[0].Rows[0]["step_number"].ToString()); // return RedirectToAction("UserLogin", "Login"); // } // } // else // { // LoanSetupStep loanStep = new LoanSetupStep(); // DataSet dsLoanStepNo = new DataSet(); // dsLoanStepNo = step.checkUserLoginWhileLoanSetup(userData); // if (dsLoanStepNo.Tables[0].Rows.Count > 0) // { // loanStep.CompanyId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["company_id"].ToString()); // loanStep.BranchId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["branch_id"].ToString()); // loanStep.stepId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["step_number"].ToString()); // loanStep.nonRegisteredBranchId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["non_registered_branch_id"].ToString()); // if (dsLoanStepNo.Tables[0].Rows[0]["loan_id"].ToString() != "") // { // loanStep.loanId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["loan_id"].ToString()); // } // else // { // loanStep.loanId = 0; // } // Session["loanStep"] = loanStep; // if (userData.RoleId == 1) // { // return RedirectToAction("Step" + (loanStep.stepId + 5), "SetupProcess"); // } // } // else // { // //Redirect to Super Admin dashboard // return RedirectToAction("UserDetails", "UserManagement"); // } // } // } // else // { // //if step table has record pass(company id and branch id) // DataSet dsStepNo = new DataSet(); // dsStepNo = step.checkUserLoginWhileCompanySetup(userData); // if (dsStepNo.Tables[0].Rows.Count > 0) // { // Session["companyStep"] = int.Parse(dsStepNo.Tables[0].Rows[0]["step_number"].ToString()); // if (userData.RoleId == 2) // { // return RedirectToAction("Index", "SetupProcess"); // } // else // { // return RedirectToAction("UserLogin", "Login", new { lbl = "Company setup process is on going please contact admin." }); // } // } // else // { // //No Step recor in relavent Company and branch // LoanSetupStep loanStep = new LoanSetupStep(); // DataSet dsLoanStepNo = new DataSet(); // dsLoanStepNo = step.checkUserLoginWhileLoanSetup(userData); // if (dsLoanStepNo.Tables[0].Rows.Count > 0) // { // loanStep.CompanyId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["company_id"].ToString()); // loanStep.BranchId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["branch_id"].ToString()); // loanStep.stepId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["step_number"].ToString()); // loanStep.nonRegisteredBranchId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["non_registered_branch_id"].ToString()); // if (dsLoanStepNo.Tables[0].Rows[0]["loan_id"].ToString() != "") // { // loanStep.loanId = int.Parse(dsLoanStepNo.Tables[0].Rows[0]["loan_id"].ToString()); // } // else // { // loanStep.loanId = 0; // } // Session["loanStep"] = loanStep; // if (userData.RoleId == 2) // { // //return RedirectToAction("Index", "SetupProcess"); // return RedirectToAction("Step" + (loanStep.stepId+5), "SetupProcess"); // } // } // else // { // if (userData.RoleId == 2) // { // //Redirect to Branch Admin dashboard // return RedirectToAction("UserDetails", "UserManagement"); // } // else // { // //Redirect to User dashboard // return RedirectToAction("UserDetails", "UserManagement"); // } // } // } // } // } //} //else //{ // //User Name Correct but user enter password does not match with database password value // return RedirectToAction("UserLogin", "Login", new { lbl = "Incorrect Username or Password, please confirm and submit." }); //} //insert log entry } else { //User Name Correct but user enter password does not match with database password value Log log = new Log(userData.UserId, userData.Company_Id, userData.BranchId, 0, "User Login", "User : "******" was unable to login, Entered password did not match ", DateTime.Now); int islog = (new LogAccess()).InsertLog(log); return(RedirectToAction("UserLogin", "Login", new { lbl = "Incorrect Username & Password combination. Please confirm entry and resubmit." })); } } else { //Incorrect UserName Log log = new Log(userData.UserId, userData.Company_Id, userData.BranchId, 0, "User Login", "User : "******" was unable to login, Entered username did not exist ", DateTime.Now); int islog = (new LogAccess()).InsertLog(log); return(RedirectToAction("UserLogin", "Login", new { lbl = "Incorrect Username & Password combination. Please confirm entry and resubmit." })); } } catch { return(RedirectToAction("UserLogin", "Login", new { lbl = "An error has occurred.Please try again later" })); } return(RedirectToAction("UserLogin", "Login")); }
public ActionResult LinkDealer(DealerUserModel user) { //initialize properties of user object user.PhoneNumber = user.PhoneNumber2; user.CreatedBy = userData.UserId; user.IsDelete = false; user.Status = true; user.Company_Id = userData.Company_Id; user.BranchId = userData.BranchId; user.RoleId = 4; user.Email = user.NewEmail; BranchAccess ba = new BranchAccess(); Loan loan = new Loan(); //Check Session["oneLoanDashboard"] is not null if (Session["oneLoanDashboard"] != null) { //convert session object to loan object loan = (Loan)Session["oneLoanDashboard"]; } //Check Session["loanDashboardJoinDealer"] is not null if (Session["loanDashboardJoinDealer"] != null) { //convert session object to loan object loan = (Loan)Session["loanDashboardJoinDealer"]; } //initialize non registered branch id user.NonRegBranchId = loan.NonRegBranchId; //initialize loan id user.LoanId = loan.LoanId; //encrypt given password string passwordTemp = user.Password; UserAccess ua = new UserAccess(); string newSalt = PasswordEncryption.RandomString(); user.Password = PasswordEncryption.encryptPassword(user.Password, newSalt); user.ActivationCode = Guid.NewGuid().ToString(); //report rights string[] arrList = new string[user.ReportRightsList.Count]; int k = 0; foreach (var y in user.ReportRightsList) { //Check whether a particular report right is given to user if (y.active) { arrList[k] = y.rightId; k++; } } arrList = arrList.Where(x => !string.IsNullOrEmpty(x)).ToArray(); user.ReportRights = string.Join(",", arrList); //Insert dealer user details and retrieve user id of inserted user int newUserId = ua.InsertDealerUser(user); //Check user id is not 0 if (newUserId != 0) { //Generate email to send username and password to created dealer user string body = "Hi " + user.FirstName + "! <br /><br /> Your account has been successfully created. Below in your account detail." + "<br /><br /> User name: " + user.UserName + "<br /> Password : <b>" + passwordTemp + "<br />Click <a href='www.dfpso.com'>here</a> to activate your account." + "<br /><br/> Thanks,<br /> Admin."; Email email = new Email(user.Email); Session["abcRol"] = user.RoleId; Session["abcBrnc"] = user.BranchId; email.SendMail(body, "Account details"); //insert log record after user is created Log log = new Log(userData.UserId, userData.Company_Id, user.BranchId, user.LoanId, "Create Dealer Account", "Inserted Dealer : " + user.UserName, DateTime.Now); int islog = (new LogAccess()).InsertLog(log); TempData["msg"] = 1; return(RedirectToAction("LinkDealer")); } else { TempData["msg"] = 2; return(RedirectToAction("LinkDealer")); } }
public ActionResult UpdatePassword(string new_password, string old_password, string new_password_reenter) { 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") { ModelState.Clear(); existing_user_data = db.tb_user.Where(tempuser => tempuser.id == existing_user_data.id).Include(tempuser => tempuser.tb_employer_registration_data).FirstOrDefault <tb_user>(); TryValidateModel(existing_user_data); string encPassword = enc.encryptPassword(old_password); if (encPassword != existing_user_data.password) { ViewBag.ErrorMessage = "Old Password does not match"; return(View("AccountSetting", existing_user_data)); } encPassword = enc.encryptPassword(new_password); if (encPassword == existing_user_data.password) { ViewBag.ErrorMessage = "New and old Passwords should not be same"; return(View("AccountSetting", existing_user_data)); } if (new_password != new_password_reenter) { ViewBag.ErrorMessage = "New Password and Re enter Password should be same"; return(View("AccountSetting", existing_user_data)); } if (new_password.Length < 6 || new_password.Length > 32) { ViewBag.ErrorMessage = "Password Length must be atleast 6 Characters"; return(View("AccountSetting", existing_user_data)); } existing_user_data.password = new_password; TryValidateModel(existing_user_data); if (ModelState.IsValid) { existing_user_data.password = encPassword; existing_user_data.last_change_password = old_password; db.Entry(existing_user_data).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Session["user"] = existing_user_data; 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(View("DbError", "User", e)); } return(View("AccountSetting")); }
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"); }
public ActionResult Create(User user) { int currentUser = 0; try { currentUser = int.Parse(Session["userId"].ToString()); } catch (Exception) { return(RedirectToAction("UserLogin", "Login")); } user.CreatedBy = _createById; user.IsDelete = false; user.Status = false; //Set admin branch to new user if (_curUserRoleId == 2) { user.BranchId = _curBranchId; } //Check role is selected if (user.RoleId == 0) { user.RoleId = 2; } //Check branch is selected if (_curUserRoleId == 1 && user.BranchId == 0) { user.BranchId = _curBranchId; } string passwordTemp = user.Password; UserAccess ua = new UserAccess(); string newSalt = PasswordEncryption.RandomString(); user.Password = PasswordEncryption.encryptPassword(user.Password, newSalt); user.Email = user.NewEmail; //Check this CompanyAccess ca = new CompanyAccess(); Company company = new Company();//ca.GetCompanyDetailsByFirstSpUserId(currentUser); //Insert user user.Company_Id = company.CompanyId; int res = ua.InsertUser(user); //Insert new user to user activation table string activationCode = Guid.NewGuid().ToString(); int userId = (new UserAccess()).getUserId(user.Email); res = ua.InsertUserActivation(userId, activationCode); if (res == 1) { ViewBag.SuccessMsg = "Data Successfully inserted!"; string body = "Hi " + user.FirstName + "! <br /><br /> Your account has been successfully created. Below in your account detail." + "<br /><br /> User name: " + user.UserName + "<br /> Password : <b>" + passwordTemp + "<br />Click <a href='http://localhost:57318/CreateUser/ConfirmAccount?userId=" + userId + "&activationCode=" + activationCode + "'>here</a> to activate your account." + "<br /><br/> Thanks,<br /> Admin."; Email email = new Email(user.Email); email.SendMail(body, "Account details"); // check the user as superadmin or admin.. if (user.RoleId == 1 || user.RoleId == 2) { ViewBag.SuccessMsg = "User Successfully Created"; return(RedirectToAction("create", new { lbls = ViewBag.SuccessMsg })); } Session["editUserIds"] = userId; return(RedirectToAction("SetRights", "EditRights", new { @lbl1 = ViewBag.SuccessMsg })); } else { ViewBag.ErrorMsg = "Failed to create user!"; //Restrict to create above user role RoleAccess ra = new RoleAccess(); List <UserRole> roleList = ra.GetAllUserRoles(); List <UserRole> tempRoleList = new List <UserRole>(); for (int i = roleList[_curUserRoleId - 1].RoleId; i <= roleList.Count && _curUserRoleId != 3; i++) { UserRole tempRole = new UserRole() { RoleId = roleList[i - 1].RoleId, RoleName = roleList[i - 1].RoleName }; tempRoleList.Add(tempRole); } ViewBag.RoleId = new SelectList(tempRoleList, "RoleId", "RoleName"); // get all branches List <Branch> branchesLists = (new BranchAccess()).getBranches(_companyId); ViewBag.BranchId = new SelectList(branchesLists, "BranchId", "BranchName"); return(PartialView("Create")); } }
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 }