Exemplo n.º 1
0
        public JsonResult Login(string userName, string password, string backUrl, string vercode)
        {
            if (string.IsNullOrEmpty(vercode))
            {
                return(Json(new JsonResultModel {
                    Message = "请输入验证码!"
                }));
            }
            if (!VerCode.CheckVerifyCode(vercode))
            {
                return(Json(new JsonResultModel {
                    Message = "验证码错误,请重新输入!"
                }));
            }
            var user = UsersLogin.LoginByUserName(userName, password);

            if (user == null || user.IsNull)
            {
                return(Json(new JsonResultModel {
                    Message = "用户名或密码错误!"
                }));
            }
            if (string.IsNullOrEmpty(backUrl))
            {
                backUrl = Url.Action("Index", "Home");
            }

            return(Json(new JsonResultModel {
                Message = "登陆成功", ResultState = true, Action = backUrl
            }));
        }
Exemplo n.º 2
0
        public ActionResult ForgetPassword(string email, string vercode)
        {
            if (string.IsNullOrEmpty(email))
            {
                return(Json(new JsonResultModel {
                    Message = "请输入您的邮箱地址!"
                }));
            }
            if (string.IsNullOrEmpty(vercode))
            {
                return(Json(new JsonResultModel {
                    Message = "请输入验证码!"
                }));
            }
            if (!VerCode.CheckVerifyCode(vercode))
            {
                return(Json(new JsonResultModel {
                    Message = "验证码错误,请重新输入!"
                }));
            }
            UserVModel user;

            if (UserIsLogin)
            {
                //已登陆
                user = Users.GetUserById(CurrentUserInfo.Id);
                if (user == null || user.IsNull)
                {
                    return(Json(new JsonResultModel {
                        Message = "您的信息有误,操作失败!"
                    }));
                }
                if (user.Email.ToLower() != email.ToLower())
                {
                    return(Json(new JsonResultModel {
                        Message = "您的邮箱有误,请确认您个人信息中的邮箱!"
                    }));
                }
            }
            else
            {
                //未登陆
                //先查出用户id
                user = Users.GetUserByEmail(email);
                if (user == null || user.IsNull)
                {
                    return(Json(new JsonResultModel {
                        Message = "您的邮箱地址不存在,请您确认!"
                    }));
                }
            }

            #region 发送邮件限制检测
            string msg;
            bool   checkResult = SendMailLogsPublic.CheckUserEmailAvailable(user.Id, UserConfig.SendEmailInterval,
                                                                            UserConfig.SendEmailIntervalMaxNum, UserConfig.SendEmailToDayMaxNum, out msg);
            if (!checkResult)
            {
                return(Json(new JsonResultModel {
                    Message = msg
                }));
            }
            #endregion

            #region 写入令牌信息
            IToken token     = new EmailActivateToken(user.Id, user.Email);
            string tokenCode = token.GetToken();
            var    tokeninfo = new UserActivateTokenVModel()
            {
                UserId = user.Id,
                Email  = user.Email,
                Token  = tokenCode
            };
            long id = UserActivateTokensPublic.Add(tokeninfo);
            if (id <= 0)
            {
                return(Json(new JsonResultModel {
                    Message = "写入令牌信息失败,请重试!"
                }));
            }
            #endregion

            #region 发送激活邮件
            string title  = WebSysConfig.WebName + "找回密码邮件";
            var    values = new Dictionary <string, object>
            {
                { "$Title", title },
                { "$Url", "http://" + Request.Url.Host + Url.Action("forgetpassword", "user", new{ token = tokenCode }) },
                { "$WebName", WebSysConfig.WebName },
                { "$TimeDsc", WebSysConfig.RetrievePasswordTokenExpireTime + "分钟内" }
            };
            bool status = UserPublic.SendMail(user.Id, user.Id, Common.Fetch.Ip, user.Email, EmailTemplateConfig.RetrievePasswordEmailTemplate, values, "UTF-8", true);
            if (status)
            {
                return(Json(new JsonResultModel {
                    ResultState = true, Message = "邮件发送成功,请进入邮箱进行操作!"
                }));
            }
            #endregion

            return(Json(new JsonResultModel {
                Message = "邮件发送失败!"
            }));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Add(VWModel.ArticleVModel model, string vercode)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new JsonResultModel {
                    Message = ModelStateHelper.GetAllErrorMessage(ModelState)
                }));
            }
            if (string.IsNullOrEmpty(vercode))
            {
                return(Json(new JsonResultModel {
                    Message = "请输入验证码!"
                }));
            }
            if (!VerCode.CheckVerifyCode(vercode))
            {
                return(Json(new JsonResultModel {
                    Message = "验证码错误,请重新输入!"
                }));
            }

            if (!ArticlesPublic.CheckCanPost(CurrentUserInfo.Id, Site.Config.UserConfig.AddArticleInterval))
            {
                return(Json(new JsonResultModel {
                    Message = "操作速度太快了,喝口水再试一下!"
                }));
            }
            model.UserId         = CurrentUserInfo.Id;
            model.LastEditUserId = CurrentUserInfo.Id;
            var user = Users.GetUserById(CurrentUserInfo.Id);

            if (user == null || user.IsNull)
            {
                return(Json(new JsonResultModel {
                    Message = "用户信息异常!"
                }));
            }
            var role = Roles.GetRole(user.RoleId);

            if (role == null || role.IsNull)
            {
                return(Json(new JsonResultModel {
                    Message = "角色信息异常!"
                }));
            }
            //根据角色判断是否需要审核
            model.State = (short)(role.ArticleNeedVerified?0:1);

            long id = await ArticlesPublic.Add(model);

            if (id <= 0)
            {
                return(Json(new JsonResultModel {
                    Message = "提交失败!"
                }));
            }
            await UserPublic.UpdateArticleNum(CurrentUserInfo.Id, 1);

            return(Json(new JsonResultModel {
                ResultState = true, Message = "发表成功!", Action = Url.Action("Detail", "Article", new{ aid = id })
            }));
        }