public ActionResult Login(EmployerLogin login, Job j) { var Employer = su.EmployerCompany.FirstOrDefault(u => u.EmployerMail == login.EmployerMail && u.Password == login.Password); var User = su.User.FirstOrDefault(u => u.UserEmail == login.EmployerMail && u.Password == login.Password); if (Employer != null) { Response.Cookies["name"].Value = HttpUtility.UrlEncode(Employer.CompanyName); Response.Cookies["nameid"].Value = Employer.CompanyID.ToString(); if (login.RememberMe) { Response.Cookies["name"].Expires = DateTime.Now.AddDays(7); } return(RedirectToAction("JobManage", "Manager")); //int.Parse(Request.Cookies["nameID"].Value) } else if (User != null) { Response.Cookies["name"].Value = HttpUtility.UrlEncode(User.UserName); Response.Cookies["nameid"].Value = (-User.UserID).ToString(); if (login.RememberMe) { Response.Cookies["name"].Expires = DateTime.Now.AddDays(7); } return(RedirectToAction("Index", "Home")); } ViewBag.error = "帳號或密碼錯誤"; return(View()); }
public ActionResult Login(EmployerLogin login) { //验证验证码 if (Session["VerificationCode"] == null || Session["VerificationCode"].ToString() == "") { Error _e = new Error { Title = "验证码不存在", Details = "在用户注册时,服务器端的验证码为空,或向服务器提交的验证码为空", Cause = Server.UrlEncode("<li>你注册时在注册页面停留的时间过久页已经超时</li><li>您绕开客户端验证向服务器提交数据</li>"), Solution = Server.UrlEncode("返回<a href='" + Url.Action("Register", "Employer") + "'>注册</a>页面,刷新后重新注册") }; return(RedirectToAction("Error", "Prompt", _e)); } else if (Session["VerificationCode"].ToString() != login.VerificationCode.ToUpper()) { ModelState.AddModelError("VerificationCode", "×"); return(View()); } //验证账号密码 int ans = Employer.LoginAuthentication(login.EmployerAccount, Common.Text.EnCrypt(login.EmployerPwd)); if (ans == 1 || ans == 2) { //登录成功则根据账号得到雇主信息 Employer employer = GetEmployerDetailsByAccount(login.EmployerAccount); HttpCookie _cookie = new HttpCookie("Employer"); _cookie.Values.Add("EmployerAccount", login.EmployerAccount); //密码先用自己的加密方法,再url加密(防止自己加密后有特殊字符),再存到cookie里 //取用的时候,先url解密,再用自己方法解密 _cookie.Values.Add("EmployerPwd", Server.UrlEncode(Common.Text.EnCrypt(login.EmployerPwd))); _cookie.Values.Add("IsDelete", (employer.IsDelete).ToString()); Response.Cookies.Add(_cookie); if (Request.QueryString["ReturnUrl"] != null) { return(Redirect(Request.QueryString["ReturnUrl"])); } else { return(RedirectToAction("Index", "Employer")); } } else if (ans == 0) { ModelState.AddModelError("Message", "账号或密码错误,登陆失败!"); return(View()); } return(View()); }
public ActionResult Submitted(IEnumerable <Interactive_Internship_Application.Models.ApplicationTemplate> ApplicationTemplateModel, string response) { string result = response; //used to determine if a new Student App Num needs to be created //below gets the student's email using queries var studentsEmail = (from student in _dataContext.StudentInformation where student.Email == User.Identity.Name.ToString() select student.Email).FirstOrDefault(); //save submitted information into a dictionary var dict = Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString()); //get employer email from submitted information (will need to be used whether or //not a new application is created var employerEmail = ""; foreach (var item in dict) { string key = item.Key; if (key.Contains("class_enrolled") || key.Contains("supervisors_email")) { if (key.Contains("supervisors_email")) { employerEmail = dict[key]; } //class enrolled and employer email must be entered //show error message if not entered if (dict[key].Length < 0) { ViewBag.error = "Class enrolled and employer email must be entered in order to save or submit"; return(RedirectToAction("Application")); } } } //determine if new StudentAppNum needs to be created if (response == "Submit New Application" || response == "Save New Application") { //generate random number pin (4 digits) for employer Random rnd = new Random(); int pin = rnd.Next(0000, 9999); //save employer email, pin, and student email to Employer Login Table EmployerLogin newEmployerLogin = new EmployerLogin(); newEmployerLogin.StudentEmail = studentsEmail; newEmployerLogin.Email = employerEmail; newEmployerLogin.Pin = Convert.ToInt16(pin); newEmployerLogin.LastLogin = DateTime.Now; _dataContext.EmployerLogin.Add(newEmployerLogin); _dataContext.SaveChanges(); //save student email, employer ID, and application status to Student App Num Table StudentAppNum newApp = new StudentAppNum(); newApp.StudentEmail = studentsEmail; newApp.EmployerId = (from application in _dataContext.EmployerLogin where application.StudentEmail == studentsEmail && application.Email == employerEmail select application.Id).FirstOrDefault(); newApp.Status = "Incomplete"; _dataContext.StudentAppNum.Add(newApp); _dataContext.SaveChanges(); } //used to determine which Student App Num ID to use int empId = (from application in _dataContext.EmployerLogin where application.StudentEmail == studentsEmail && application.Email == employerEmail select application.Id).FirstOrDefault(); //get students record ID var currStudentRecordId = (from stuAppNum in _dataContext.StudentAppNum where stuAppNum.StudentEmail == studentsEmail && stuAppNum.EmployerId == empId select stuAppNum.Id).FirstOrDefault(); //get number of fields student enters int numStudentFieldCount = (from x in _dataContext.ApplicationTemplate where x.Entity == "Student" select x).Count(); //determine if student wants to submit or save application //if saving application, doesn't matter if everything was input; just make sure //class enrolled and employer email is input if (response.Contains("Save")) { Save(dict, currStudentRecordId, numStudentFieldCount); } //if submitting application, ensure everything is entered by student else if (response.Contains("Submit")) { foreach (var rec in dict) { if (rec.Value.Length <= 0) { return(View("Application")); } } //if program reaches here, all data has been entered and student wants to submit application Save(dict, currStudentRecordId, numStudentFieldCount); //send email to employer //if submitting application, ensure everything is saved in database //get employer's pin var empPin = (from empData in _dataContext.EmployerLogin where empData.Email == employerEmail select empData.Pin).FirstOrDefault(); short employerPin = Convert.ToInt16(empPin); //get employer's Company name var employerCompanyName = (from appData in _dataContext.ApplicationData join appTemp in _dataContext.ApplicationTemplate on appData.DataKeyId equals appTemp.Id where appData.RecordId == currStudentRecordId && appTemp.FieldName == "org_name" select appData.Value).FirstOrDefault(); //get student's name var studentName = (from appData in _dataContext.ApplicationData join appTemp in _dataContext.ApplicationTemplate on appData.DataKeyId equals appTemp.Id where appData.RecordId == currStudentRecordId && appTemp.FieldName == "name" select appData.Value).FirstOrDefault(); //get class student is trying to enroll in var classEnrolled = (from appData in _dataContext.ApplicationData join appTemp in _dataContext.ApplicationTemplate on appData.DataKeyId equals appTemp.Id where appData.RecordId == currStudentRecordId && appTemp.FieldName == "class_enrolled" select appData.Value).FirstOrDefault().ToString(); string emailHost = configuration["Email:Smtp:Host"]; string emailPort = configuration["Email:Smtp:Port"]; string emailUsername = configuration["Email:Smtp:Username"]; string emailPassword = configuration["Email:Smtp:Password"]; Global.EmailsGenerated emailsGenerated = new EmailsGenerated(); emailsGenerated.StudentToEmployerEmail(emailHost, emailPort, emailUsername, emailPassword, studentName, employerEmail, employerCompanyName, employerPin, classEnrolled); //change student's application status to "Pending Employer Approval" // var changeStatusApp = new StudentAppNum { Id = currStudentRecordId,StudentEmail = studentsEmail,EmployerId =empId, Status ="Incomplete" }; StudentAppNum changeStatusApp = (from appNum in _dataContext.StudentAppNum where appNum.Id == currStudentRecordId select appNum).FirstOrDefault(); changeStatusApp.Status = "Pending Employer Approval"; _dataContext.SaveChanges(); } return(View("Index")); }