/// <summary> /// 作者:Primo /// 时间:2015.05.14 /// 描述:修改, userName以字符串形式进入 /// </summary> /// <param name="model"></param> /// <returns></returns> public FunctionResult<StudentInfo> Login(AccountModel model) { //判断学生 var resultTemp = UserBLL.UserLoginValidate(model.UserName, model.Password); var result = new FunctionResult<StudentInfo>() { Status = resultTemp.Status, Info = resultTemp.Info }; if (resultTemp.Status) { //判断该用户的用户类型是不是学生 if (resultTemp.UserType.ToString() == Enum.ConvertEnum.UserTypeForStudent.ToString()) result.ReturnValue = StudentBLL.GetStudentInfoByUserName(model.UserName); else//不是学生则可以拥有所有产品操作 { result.ReturnValue = UserBLL.GetEWorkBookUserInfoByUserName(model.UserName); result.ReturnValue.ProduntIds = new int[3] { 1, 2, 3 }; } } return result; }
/// <summary> /// 作者:Primo /// 时间:2015.05.14 /// 描述:用户登录验证,去除用户类型的判断,预留日后三个端口统一使用 /// </summary> /// <param name="userName"></param> /// <param name="userPassword"></param> /// <param name="userType"></param> /// <returns></returns> public static FunctionResult UserLoginValidate(string userName, string userPassword) { var result = new FunctionResult(); using (var edb = new EmeEntities(dbRead)) { var user = edb.User.SingleOrDefault(p => p.Status == ConvertEnum.StatusTypeForActive && (p.UserName == userName || p.Email == userName || p.Mobile == userName)); if (user != null) { if (!user.Password.Equals(userPassword, StringComparison.CurrentCultureIgnoreCase)) { result.Status = false; result.Info = "PassWord Error"; } else if (user.Status != CommonHelper.To<int>(StatusType.Active)) { result.Status = false; result.Info = "Account freeze, please contact your administrator"; } else { result.Status = true; result.Info = "Successful"; result.ReturnValue = user.Id; result.ReturnUserName = user.UserName; result.UserType = user.UserType; } } else { result.Status = false; result.Info = "User name does not exist"; } return result; } }
/// <summary> /// 作者:Vincen /// 时间:2014.04.25 /// 描述:用户登录验证 /// -------------------------------- /// 更新:Vincen /// 时间:2014.04.30 /// 描述:增加手机号、邮箱的登录 /// </summary> /// <param name="userName"></param> /// <param name="userPassword"></param> /// <param name="userType"></param> /// <returns></returns> public static FunctionResult UserLoginValidate(string userName, string userPassword, UserType userType) { var uType = CommonHelper.To<int>(userType); var result = new FunctionResult(); using (var edb = new EmeEntities(dbRead)) { var user = edb.User.SingleOrDefault(p => p.Status == ConvertEnum.StatusTypeForActive && (p.UserName == userName || p.Email == userName || p.Mobile == userName)); if (user != null) { if (!user.Password.Equals(userPassword, StringComparison.CurrentCultureIgnoreCase)) { result.Status = false; result.Info = "PassWord Error"; } else if (user.Status != CommonHelper.To<int>(StatusType.Active)) { result.Status = false; result.Info = "Account freeze, please contact your administrator"; } else { if (userType == UserType.Teacher) { var teacher = edb.Teacher.FirstOrDefault(p => p.UserId == user.Id && p.Status == ConvertEnum.StatusTypeForActive); if (null != teacher) { result.Status = true; result.Info = "successful"; result.ReturnValue = user.Id; } else { result.Status = false; result.Info = "并非教师帐号"; } } else if (userType == UserType.Employee) { var employee = edb.User.FirstOrDefault(p => p.Id == user.Id && p.UserType == uType && p.Status == ConvertEnum.StatusTypeForActive); if (null != employee) { result.Status = true; result.Info = "successful"; result.ReturnValue = user.Id; } else { result.Status = false; result.Info = "并非员工帐号"; } } else if (userType == UserType.Student) { var student = edb.Student.FirstOrDefault(p => p.UserId == user.Id && p.Status == ConvertEnum.StatusTypeForActive); if (null != student) { result.Status = true; result.Info = "登录成功"; result.ReturnValue = user.Id; result.ReturnUserName = student.User.UserName; } else { result.Status = false; result.Info = "并非学员帐号"; } } else { result.Status = true; result.Info = "登录成功"; result.ReturnValue = user.Id; } } } else { result.Status = false; result.Info = "User name does not exist"; result.Info = "用户名不存在"; } return result; } }
/// <summary> /// 作者:Leo_ml /// 时间:2014.05.09 /// 描述:更新用户验证随机码 /// </summary> /// <param name="userId"></param> /// <param name="validateCode"></param> /// <param name="validateTime"></param> /// <returns></returns> public static FunctionResult UpdateUserValidateCode(int userId, string validateCode, DateTime validateTime) { using (var edb = new EmeEntities()) { var result = new FunctionResult { Status = false, Info = "修改用户验证随机码失败!" }; var user = edb.User.SingleOrDefault(p => p.Id == userId); if (user == null) return result; user.ValidateCode = validateCode; user.ValidateTime = validateTime; edb.Entry(user).State = EntityState.Modified; result.Status = edb.SaveChanges() > 0; result.Info = "修改用户验证随机码成功!"; return result; } }
/// <summary> /// 作者:Leo_ml /// 时间:2014.05.09 /// 描述:设置新密码 /// </summary> /// <param name="userId"></param> /// <param name="newPassword"></param> /// <returns></returns> public static FunctionResult SetNewPassword(int userId, string newPassword) { using (var edb = new EmeEntities()) { var result = new FunctionResult { Status = false, Info = "修改密码失败!" }; var user = edb.User.SingleOrDefault(p => p.Id == userId); if (user == null) return result; user.Password = newPassword; user.UpdateTime = DateTime.Now; edb.Entry(user).State = EntityState.Modified; result.Status = edb.SaveChanges() > 0; result.Info = "修改密码成功!"; return result; } }
/// <summary> /// 描述:修改密码 /// 作者:Raymond /// 日期:2013-11-4 /// -------------------------------- /// 更新:Vincen /// 时间:2013.12.06 /// </summary> /// <param name="userName">旧密码</param> /// <param name="newPassword">新密码</param> /// <returns></returns> public static FunctionResult ChangePassword(string userName, string newPassword) { using (var edb = new EmeEntities()) { var result = new FunctionResult { Status = false, Info = "修改密码失败!" }; var user = edb.User.SingleOrDefault(p => p.UserName == userName || p.Email == userName || p.Mobile == userName); if (user == null) return result; user.Password = newPassword; edb.Entry(user).State = EntityState.Modified; result.Status = edb.SaveChanges() > 0; result.Info = "修改密码成功!"; return result; } }
/// <summary> /// 作者:Primo /// 时间:2015.05.14 /// 描述:修改, userName以字符串形式进入 /// </summary> /// <param name="userName"></param> /// <param name="courseId"></param> /// <returns></returns> public FunctionResult IsExistsCourse(string userName, int courseId) { var funResult = new FunctionResult(); funResult.Status = StudentBLL.IsExistsCourse(userName, courseId); return funResult; }
/// <summary> /// 作者:Primo /// 时间:2015.08.25 /// 描述:薏米同学跳转登录 /// </summary> /// <param name="Token"></param> /// <returns></returns> public ActionResult LoginEme(string Token) { var result = new FunctionResult(); try { var strToken = SecurityHelper.Decrypt(Token); var model = JsonHelper.FromJson<AccountModel>(strToken); var dtNow = DateTime.Now; if (dtNow > model.ActiveDate)//登录超时 { result.Info = "链接已过期"; ViewBag.Tiper = result; } else//判断登录 { //直接获取用户 var loginUserModel = UserBLL.GetUserByUserName(model.UserName); LoginUserCache.UpdateLoginUserCacheForLogin(loginUserModel.Id.ToString()); var loginUser = LoginUserCache.GetLoginUserCacheByKey(loginUserModel.Id.ToString()); if (loginUser == null) { ViewBag.Tiper = new FunctionResult() { Status = false, Info = "登录异常,请与管理员联系!", ReturnValue = null }; return View("Login", model); } LoginUserManager.SignLoginUser(loginUser); return RedirectToAction("Index", "Home"); } return View("Login", model); } catch (Exception ex) { result.Info = "登录出错"; ViewBag.Tiper = result; return View("Login"); } }