public ActionResult RefreshCaptcha() { string path = string.Format("/Captchas/{0}.jpg", Guid.NewGuid()); string captcha = CaptchaHelper.Captcha(Server.MapPath(path)); Session.SetCaptcha(captcha); return(Json(path, JsonRequestBehavior.AllowGet)); }
static void Main(string[] args) { //using (FluentModel db = new FluentModel()) //{ // db.UpdateSchema(); // db.InitData(); //} //FTPHelper helper = new FTPHelper("ftp://202.104.69.206/Data/Upload", "admin", "suncereltd@2017"); for (int i = 0; i < 10; i++) { System.Console.WriteLine(CaptchaHelper.Captcha(string.Format("D:\\captcha41{0}.jpg", i), 4, 1)); System.Console.WriteLine(CaptchaHelper.Captcha(string.Format("D:\\captcha52{0}.jpg", i), 5, 2)); System.Console.WriteLine(CaptchaHelper.Captcha(string.Format("D:\\captcha63{0}.jpg", i), 6, 3)); System.Console.WriteLine(CaptchaHelper.Captcha(string.Format("D:\\captcha74{0}.jpg", i), 7, 4)); } System.Console.ReadLine(); }
public ActionResult Login3(string returnUrl) { if (string.IsNullOrWhiteSpace(returnUrl)) { returnUrl = Request.ApplicationPath; } SuncereUser user = Session.GetCurrentUser(); if (user == null) { ViewData["returnUrl"] = returnUrl; string path = string.Format("/Captchas/{0}.jpg", Guid.NewGuid()); string captcha = CaptchaHelper.Captcha(Server.MapPath(path)); Session.SetCaptcha(captcha); ViewData["captchaPath"] = path; return(View()); } else { return(Redirect(returnUrl)); } }
public ActionResult Login3(string userName, string password, string captcha, string returnUrl) { try { if (string.IsNullOrEmpty(userName)) { throw new Exception("请输入用户名"); } if (string.IsNullOrEmpty(password)) { throw new Exception("请输入密码"); } if (string.IsNullOrEmpty(captcha)) { throw new Exception("请输入验证码"); } if (captcha != Session.GetCaptcha()) { throw new Exception("验证码错误,请核对后重新登录"); } FluentModel db = Session.GetFluentModel(); SuncereUserRepository userRepository = new SuncereUserRepository(db); SuncereUser user = userRepository.FirstOrDefault(userName, true); if (user == null) { throw new Exception("用户名不存在或已停用,请核对后重新登录"); } if (AsymmetricEncryption.Default.Decrypt(user.Password) != password) { throw new Exception("密码错误,请核对后重新登录"); } user.LastLoginTime = DateTime.Now; user.LastLoginHostAddress = Request.UserHostAddress; db.SaveChanges(); Session.SetCurrentUser(user); List <SuncerePermission> userPermissions = new List <SuncerePermission>(); foreach (SuncereRole role in user.SuncereRoles.Where(o => o.Status)) { foreach (SuncerePermission permission in role.SuncerePermissions.Where(o => o.Status)) { if (!userPermissions.Contains(permission)) { userPermissions.Add(permission); } } } Session.SetUserPermissions(userPermissions); return(Redirect(returnUrl)); } catch (Exception e) { ViewData["message"] = e.Message; string path = string.Format("/Captchas/{0}.jpg", Guid.NewGuid()); captcha = CaptchaHelper.Captcha(Server.MapPath(path)); Session.SetCaptcha(captcha); ViewData["captchaPath"] = path; return(View()); } }