Exemple #1
0
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                BaseResponse br = DBUserBLL.CheckEmailIsExist(model.Email, 0);
                if (br.IsSuccess && br.ResponseObj != null)
                {
                    Inpinke_User user = br.ResponseObj as Inpinke_User;
                    //重置验证码生成规则,用户邮箱加上当前日期,所以每个码的有效期都是一天
                    MD5Encrypt md5          = new MD5Encrypt();
                    string     validate     = md5.GetMD5FromString(user.Email + DateTime.Now.ToString("yyyyMMdd"));
                    string     mailTemplate = ConfigHelper.ReadConfig("EmailTemplate", "configuration/ResetPassword");
                    user.ValidateCode = validate;
                    DBUserBLL.UpdateUser(user);

                    ViewBag.Email = model.Email;
                    mailTemplate  = EmailHelper.ReplaceTemplateVar <Inpinke_User>(mailTemplate, user);
                    EmailHelper.SendEmail(user.Email, mailTemplate, "印品客账户重设密码");
                    return(View("ResetNotice"));
                }
                else
                {
                    ModelState.AddModelError("Email", "不存在当前邮箱账户");
                    return(View(model));
                }
            }
            else
            {
                ModelState.AddModelError("Email", "请填写正确的邮箱");
                return(View(model));
            }
        }
Exemple #2
0
        /// <summary>
        /// 判断邮箱是否存在,存在时返回true,反之为false
        /// </summary>
        /// <param name="email"></param>
        /// <param name="userid">为0时忽略,大于0时表示不包括该所属用户</param>
        /// <returns>邮箱存在时返回true,反之为false</returns>
        public static BaseResponse CheckEmailIsExist(string email, int userid)
        {
            BaseResponse br = new BaseResponse();

            br.IsSuccess = true;
            try
            {
                Inpinke_User user = InpinkeDataContext.Instance.Inpinke_Users.Get(e => e.Email == email && e.ID != userid);
                if (user != null)
                {
                    br.IsSuccess   = true;
                    br.ResponseObj = user;
                    return(br);
                }
                else
                {
                    br.IsSuccess = false;
                    return(br);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("CheckEmailIsExist Email:{0},UserID:{1},Error:{2}", email, userid, ex.ToString()));
                return(br);
            }
        }
Exemple #3
0
 public ActionResult ChangePassword(ChangePasswordModel model, string ValidateCode)
 {
     if (ModelState.IsValid)
     {
         Inpinke_User user = DBUserBLL.GetUserByValidateCode(ValidateCode);
         if (user != null)
         {
             MD5Encrypt md5 = new MD5Encrypt();
             if (ValidateCode != md5.GetMD5FromString(user.Email + DateTime.Now.ToString("yyyyMMdd")))
             {
                 ViewBag.Msg = "对不起重设密码链接已过期,请点击<a href=\"/account/resetpassword\">[重新获取]</a>";
                 return(View("error"));
             }
             else
             {
                 user.Password = model.ConfirmPassword;
                 DBUserBLL.UpdateUser(user);
                 //修改密码成功调整
                 ViewBag.Msg = "重设密码成功,请使用新密码重新登录";
                 return(View("logon"));
             }
         }
         else
         {
             ViewBag.Msg = "对不起重设密码链接已过期,请点击<a href=\"/account/resetpassword\">[重新获取]</a>";
             return(View("error"));
         }
     }
     else
     {
         ModelState.AddModelError("Password", "密码最少6位");
     }
     return(View(model));
 }
Exemple #4
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                if (DBUserBLL.CheckEmailIsExist(model.Email, 0).IsSuccess)
                {
                    ModelState.AddModelError("Email", "该邮箱已经注册过了");
                    return(View(model));
                }

                Inpinke_User user = new Inpinke_User()
                {
                    NickName = model.NickName.Trim(),
                    Password = model.Password.Trim(),
                    Email    = model.Email.Trim()
                };
                BaseResponse br = DBUserBLL.CreateUser(user);
                if (!br.IsSuccess)
                {
                    ViewBag.Msg = br.Message;
                    return(View(model));
                }
                if (br.IsSuccess)
                {
                    FormsAuthentication.SetAuthCookie(model.NickName, false);
                    return(RedirectToAction("index", "home"));
                }
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #5
0
        /// <summary>
        /// 验证用户输入的密码是否正确
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <returns>验证成功时ResponseObj为Inpinke_User实例</returns>
        public static BaseResponse ValidateUser(string email, string password)
        {
            BaseResponse br = new BaseResponse();

            br.IsSuccess = false;
            try
            {
                MD5Encrypt md5 = new MD5Encrypt();
                password = md5.GetMD5FromString(password);
                Inpinke_User user = InpinkeDataContext.Instance.Inpinke_Users.Get(e => e.Email == email && e.Password == password);
                if (user != null)
                {
                    br.IsSuccess   = true;
                    br.ResponseObj = user;
                    return(br);
                }
                else
                {
                    br.IsSuccess = false;
                    return(br);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("ValidateUser Email:{0},Password:{1},Error:{2}", email, password, ex.ToString()));
                br.IsSuccess = false;
                return(br);
            }
        }
Exemple #6
0
        public ActionResult Index(RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Msg = "输入有误,麻烦检测下";

                return(View(model));
            }
            Inpinke_User user = DBUserBLL.GetUserByID(UserSession.CurrentUser.ID);

            if (user != null)
            {
                user.Email    = model.Email;
                user.Password = model.Password;
                user.NickName = model.NickName;
                BaseResponse br = DBUserBLL.UpdateUser(user);
                if (br.IsSuccess)
                {
                    ViewBag.Msg = "修改成功";
                }
                else
                {
                    ViewBag.Msg = br.Message;
                }
            }
            return(View(model));
        }
Exemple #7
0
        public ActionResult ResetPassword(int userid, string password)
        {
            if (AdminSession.CurrentUser == null)
            {
                return(Content("{\"success\":false,\"msg\":\"您没有权限进行此操作,请重新登录\"}"));
            }

            Inpinke_User model = DBUserBLL.GetUserByID(userid);

            if (model == null)
            {
                return(Content("{\"success\":false,\"msg\":\"未找到对应的用户\"}"));
            }
            model.Password = password;
            BaseResponse br = DBUserBLL.UpdateUser(model);

            return(Content("{\"success\":" + br.IsSuccess.ToString().ToLower() + ",\"msg\":\"" + br.Message + "\"}"));
        }
Exemple #8
0
        public ActionResult LogOn(LogOnModel model, string f)
        {
            if (ModelState.IsValid)
            {
                BaseResponse br = DBUserBLL.ValidateUser(model.Email, model.Password);
                if (br.IsSuccess)
                {
                    //添加session
                    Inpinke_User loginUser = br.ResponseObj as Inpinke_User;
                    UserSession.CurrentUser = loginUser;
                    FormsAuthentication.SetAuthCookie(model.Email, model.RememberMe);
                    //设置友言单点登录cookie
                    //http://api.uyan.cc?mode=des&uid={0}&uname={1}&email={2}&uface={3}&ulink={4}&expire=3600&key=inpinke20130417
                    string loginStr = ConfigHelper.ReadConfig("UyanApi", "configuration/DESApiUrl");
                    loginStr = string.Format(loginStr, loginUser.ID, loginUser.NickName, loginUser.Email, "", "");
                    string     CookieMi   = UYanBLL.GetMi(loginStr);
                    string     cookieName = ConfigHelper.ReadConfig("UyanApi", "configuration/CookieName");
                    HttpCookie cookie     = new HttpCookie(cookieName);
                    cookie.Value = CookieMi;
                    //HttpContext.Current.Response.Cookies.Add(cookie);
                    HttpContext.Response.Cookies.Add(cookie);

                    if (Url.IsLocalUrl(f) && f.Length > 1 && f.StartsWith("/") &&
                        !f.StartsWith("//") && !f.StartsWith("/\\"))
                    {
                        return(Redirect(f));
                    }
                    else
                    {
                        return(RedirectToAction("index", "home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("Password", "电子邮箱或密码不正确");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #9
0
        public ActionResult ChangePassword(string v)
        {
            ViewBag.Validate = v;
            //判断重设验证码是否过期
            Inpinke_User user = DBUserBLL.GetUserByValidateCode(v);

            if (user == null)
            {
                ViewBag.Msg = "对不起重设密码链接已过期,请点击<a href=\"/account/resetpassword\">[重新获取]</a>";
                return(View("error"));
            }
            else
            {
                MD5Encrypt md5 = new MD5Encrypt();
                if (v != md5.GetMD5FromString(user.Email + DateTime.Now.ToString("yyyyMMdd")))
                {
                    ViewBag.Msg = "对不起重设密码链接已过期,请点击<a href=\"/account/resetpassword\">[重新获取]</a>";
                    return(View("error"));
                }
            }

            return(View());
        }
Exemple #10
0
        /// <summary>
        /// 更新用户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static BaseResponse UpdateUser(Inpinke_User model)
        {
            BaseResponse br = new BaseResponse();

            br.IsSuccess = false;
            try
            {
                MD5Encrypt md5 = new MD5Encrypt();
                model.Password   = md5.GetMD5FromString(model.Password);
                model.UpdateTime = DateTime.Now;
                model.SaveWhenSubmit(InpinkeDataContext.Instance);
                InpinkeDataContext.Instance.Submit();
                br.IsSuccess = true;
                return(br);
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("UpdateUser Email:{0},Password:{1},NickName:{2} Error:{3}", model.Email, model.Password, model.NickName, ex.ToString()));
                br.IsSuccess = false;
                br.Message   = "更新用户信息失败,请稍后再试";
                return(br);
            }
        }
Exemple #11
0
        public ActionResult Edit(int id)
        {
            Inpinke_User model = DBUserBLL.GetUserByID(id);

            return(View("Create", model));
        }