Пример #1
0
        public JsonResult Login(LoginVModel model)
        {
            var result = new JsonResultModel();

            if (ModelState.IsValid)
            {
                if (Users.IsHaveUser(model.Username))
                {
                    var userInfo = Users.GetUserInfo(model.Username, model.Password);
                    if (userInfo != null)
                    {
                        Users.Login(userInfo);
                        Users.UpdateOnLineTime(userInfo.Id);
                        result.ResultState = true;
                    }
                    else
                    {
                        result.ResultState = false;
                        result.Message     = "用户名或密码错误!";
                    }
                }
                else
                {
                    result.ResultState = false;
                    result.Message     = "用户不存在!";
                }
            }
            else
            {
                result.ResultState = false;
                result.Message     = ModelStateHelper.GetAllErrorMessage(ModelState);
            }

            return(Json(result));
        }
Пример #2
0
        public ActionResult SetPassword(UserVModel user, string oldPassword)
        {
            if (string.IsNullOrEmpty(oldPassword) || !UserPublic.CheckUserPassword(user.Id, oldPassword))
            {
                return(Json(new JsonResultModel {
                    Message = "旧密码输入错误!"
                }));
            }
            ModelState.Remove("Name");
            ModelState.Remove("NickName");
            ModelState.Remove("Sex");
            ModelState.Remove("RoleId");
            ModelState.Remove("Avatar");
            ModelState.Remove("Email");
            if (!ModelState.IsValid)
            {
                return(Json(new JsonResultModel {
                    Message = ModelStateHelper.GetAllErrorMessage(ModelState)
                }));
            }
            var status = UserPublic.UpdatePassword(user.Id, user.Password);

            return(Json(new JsonResultModel {
                ResultState = status, Message = status?"修改成功!":"修改失败!"
            }));
        }
Пример #3
0
        public JsonResult Reg(UserVModel model, string vercode)
        {
            if (string.IsNullOrEmpty(vercode))
            {
                return(Json(new JsonResultModel {
                    Message = "请输入验证码!"
                }));
            }
            if (!VerCode.CheckVerifyCode(vercode))
            {
                return(Json(new JsonResultModel {
                    Message = "验证码错误,请重新输入!"
                }));
            }
            if (Vip.UserNameIsHave(model.Name, null))
            {
                return(Json(new JsonResultModel {
                    Message = "用户名已存在"
                }));
            }
            if (Vip.NickNameIsHave(model.NickName, null))
            {
                return(Json(new JsonResultModel {
                    Message = "昵称已存在"
                }));
            }
            if (Vip.EmailIsHave(model.Email, null))
            {
                return(Json(new JsonResultModel {
                    Message = "邮箱已存在"
                }));
            }
            if (!ModelState.IsValid)
            {
                return(Json(new JsonResultModel {
                    Message = ModelStateHelper.GetAllErrorMessage(ModelState)
                }));
            }
            bool status = Vip.AddUserInfo(model);

            if (status)
            {
                string refurl = Url.Action("Login", "Vip");
                if (Request["backUrl"] != null)
                {
                    refurl += "?backUrl=" + Request["backUrl"];
                }
                return(Json(new JsonResultModel {
                    ResultState = true, Action = refurl, Message = "注册成功,快去登陆吧!"
                }));
            }

            return(Json(new JsonResultModel {
                Message = "注册失败"
            }));
        }
Пример #4
0
        public ActionResult ForgetSetPassword(UserVModel user, string token)
        {
            if (string.IsNullOrEmpty(token))
            {
                return(Json(new JsonResultModel {
                    Message = "令牌校验错误,重置失败!"
                }));
            }
            ModelState.Remove("Name");
            ModelState.Remove("NickName");
            ModelState.Remove("Sex");
            ModelState.Remove("RoleId");
            ModelState.Remove("Avatar");
            ModelState.Remove("Email");
            if (!ModelState.IsValid)
            {
                return(Json(new JsonResultModel {
                    Message = ModelStateHelper.GetAllErrorMessage(ModelState)
                }));
            }

            //通过token 得到id
            long tokenId = UserActivateTokensPublic.CheckToken(token, WebSysConfig.ActivateTokenExpireTime);

            if (tokenId <= 0)
            {
                return(Json(new JsonResultModel {
                    Message = "令牌无效,重置失败,请重新获取找密码回邮件!"
                }));
            }
            //得到token 信息
            var tokeninfo = UserActivateTokensPublic.GetUserActivateTokenVModel(tokenId);

            if (tokeninfo == null || tokeninfo.IsNull)
            {
                return(Json(new JsonResultModel {
                    Message = "令牌无效,重置失败,请重新获取找密码回邮件!"
                }));
            }
            //得到email,通过email修改密码
            bool status = UserPublic.UpdatePassword(tokeninfo.Email, user.Password);

            if (!status)
            {
                return(Json(new JsonResultModel {
                    Message = "密码重置失败,稍后再试!"
                }));
            }
            //置令牌无效
            UserActivateTokensPublic.UpdateStatus(tokenId, false);
            return(Json(new JsonResultModel {
                ResultState = true, Message = "密码重置成功,请使用新密码重新登陆!", Action = (UserIsLogin?"":Url.Action("Login", "Vip"))
            }));
        }
Пример #5
0
        public JsonResult Add(UserVModel model)
        {
            var result = new JsonResultModel();

            if (ModelState.IsValid)
            {
                //add user
                result.ResultState = Users.AddUser(Users.UserVModelToInfo(model));
            }
            else
            {
                result.ResultState = false;
                result.Message     = ModelStateHelper.GetAllErrorMessage(ModelState);
            }

            return(Json(result));
        }
Пример #6
0
        public JsonResult Edit(DianZanLogVModel model)
        {
            var result = new JsonResultModel();

            if (ModelState.IsValid)
            {
                //edit user
                result.ResultState = DianZanLogs.UpdateDianZanLog(DianZanLogs.DianZanLogVModelToInfo(model)) > 0;
            }
            else
            {
                result.ResultState = false;
                result.Message     = ModelStateHelper.GetAllErrorMessage(ModelState);
            }

            return(Json(result));
        }
Пример #7
0
        public JsonResult Add(EmailTemplateVModel model)
        {
            var result = new JsonResultModel();

            if (ModelState.IsValid)
            {
                //add
                result.ResultState = EmailTemplates.AddEmailTemplate(EmailTemplates.EmailTemplateVModelToInfo(model)) > 0;
            }
            else
            {
                result.ResultState = false;
                result.Message     = ModelStateHelper.GetAllErrorMessage(ModelState);
            }

            return(Json(result));
        }
Пример #8
0
        public JsonResult Add(CommentVModel model)
        {
            var result = new JsonResultModel();

            if (ModelState.IsValid)
            {
                //add
                result.ResultState = Comments.AddComment(Comments.CommentVModelToInfo(model)) > 0;
            }
            else
            {
                result.ResultState = false;
                result.Message     = ModelStateHelper.GetAllErrorMessage(ModelState);
            }

            return(Json(result));
        }
Пример #9
0
        public JsonResult Edit(ArticleTypeVModel model)
        {
            var result = new JsonResultModel();

            if (ModelState.IsValid)
            {
                //edit user
                result.ResultState = ArticleTypes.UpdateArticleType(ArticleTypes.ArticleTypeVModelToInfo(model)) > 0;
            }
            else
            {
                result.ResultState = false;
                result.Message     = ModelStateHelper.GetAllErrorMessage(ModelState);
            }

            return(Json(result));
        }
Пример #10
0
        public JsonResult Add(SendMailLogVModel model)
        {
            var result = new JsonResultModel();

            if (ModelState.IsValid)
            {
                //add
                result.ResultState = SendMailLogs.AddSendMailLog(SendMailLogs.SendMailLogVModelToInfo(model)) > 0;
            }
            else
            {
                result.ResultState = false;
                result.Message     = ModelStateHelper.GetAllErrorMessage(ModelState);
            }

            return(Json(result));
        }
Пример #11
0
        public JsonResult Edit(RoleModulVModel model)
        {
            var result = new JsonResultModel();

            if (ModelState.IsValid)
            {
                //edit user
                result.ResultState = RoleModuls.UpdateRoleModul(RoleModuls.RoleModulVModelToInfo(model)) > 0;
            }
            else
            {
                result.ResultState = false;
                result.Message     = ModelStateHelper.GetAllErrorMessage(ModelState);
            }

            return(Json(result));
        }
Пример #12
0
        public JsonResult Edit(UserActivateTokenVModel model)
        {
            var result = new JsonResultModel();

            if (ModelState.IsValid)
            {
                //edit user
                result.ResultState = UserActivateTokens.UpdateUserActivateToken(UserActivateTokens.UserActivateTokenVModelToInfo(model)) > 0;
            }
            else
            {
                result.ResultState = false;
                result.Message     = ModelStateHelper.GetAllErrorMessage(ModelState);
            }

            return(Json(result));
        }
Пример #13
0
        public JsonResult Add(ArticleVModel model)
        {
            var result = new JsonResultModel();

            if (ModelState.IsValid)
            {
                model.UserId = CurrentUserInfo.Id;
                //add
                result.ResultState = Articles.AddArticle(Articles.ArticleVModelToInfo(model)) > 0;
            }
            else
            {
                result.ResultState = false;
                result.Message     = ModelStateHelper.GetAllErrorMessage(ModelState);
            }

            return(Json(result));
        }
Пример #14
0
        public JsonResult Add(ArticleTypeVModel model)
        {
            var result = new JsonResultModel();

            if (ModelState.IsValid)
            {
                model.PinYin = PinYinHelper.ConvertToPinYin(model.Name);

                //add
                result.ResultState = ArticleTypes.AddArticleType(ArticleTypes.ArticleTypeVModelToInfo(model)) > 0;
            }
            else
            {
                result.ResultState = false;
                result.Message     = ModelStateHelper.GetAllErrorMessage(ModelState);
            }

            return(Json(result));
        }
Пример #15
0
        public ActionResult Edit(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 = "验证码错误,请重新输入!"
                }));
            }

            //文章作者检测
            var article = Articles.GetArticleInfoById(model.Id);

            if (article == null || article.IsNull || article.UserId != CurrentUserInfo.Id)
            {
                return(Json(new JsonResultModel {
                    Message = "您的文章不存在!"
                }));
            }

            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);

            bool status = ArticlesPublic.UpdateArticle(model);

            if (!status)
            {
                return(Json(new JsonResultModel {
                    Message = "修改失败!"
                }));
            }

            return(Json(new JsonResultModel {
                ResultState = true, Message = "修改成功!", Action = Url.Action("Detail", "Article", new { aid = model.Id })
            }));
        }
Пример #16
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 })
            }));
        }
Пример #17
0
        public async Task <ActionResult> SetInfo(UserVModel user, UserOtherVModel other, string province, string city, string area)
        {
            ModelState.Remove("Name");
            ModelState.Remove("ConfirmPassword");
            ModelState.Remove("Password");
            ModelState.Remove("RoleId");
            ModelState.Remove("Avatar");
            if (!ModelState.IsValid)
            {
                return(Json(new JsonResultModel {
                    Message = ModelStateHelper.GetAllErrorMessage(ModelState)
                }));
            }
            user.Id      = CurrentUserInfo.Id;
            other.UserId = CurrentUserInfo.Id;

            var olduser = Users.GetUserById(CurrentUserInfo.Id);

            //邮箱修改需要重新验证
            if (olduser.Email.ToLower() != user.Email.ToLower())
            {
                user.EmailStatus = false;
            }
            else
            {
                user.EmailStatus = olduser.EmailStatus;
            }

            //修改基本信息
            var status = UserPublic.UpdateUser(user);

            if (!status)
            {
                return(Json(new JsonResultModel {
                    Message = "修改基本信息失败!"
                }));
            }
            var userOther = await Users.GetUserOtherById(user.Id);

            if (userOther == null || userOther.IsNull)
            {
                status = await UserPublic.AddUserOther(other) > 0;
            }
            else
            {
                status = UserPublic.UpdateUserOther(other);
            }
            if (!status)
            {
                return(Json(new JsonResultModel {
                    Message = "修改信息失败!"
                }));
            }

            await UserPublic.DeleteUserPosition(CurrentUserInfo.Id);

            #region 地址
            if (!string.IsNullOrEmpty(province))
            {
                int pid = await
                          UserPublic.AddUserPosition(new UserPositionVModel
                {
                    Code   = int.Parse(province),
                    Type   = 0,
                    UserId = CurrentUserInfo.Id
                });

                if (pid == 0)
                {
                    return(Json(new JsonResultModel {
                        Message = "修改居住地区信息失败,!"
                    }));
                }
            }
            if (!string.IsNullOrEmpty(city))
            {
                int cid = await
                          UserPublic.AddUserPosition(new UserPositionVModel
                {
                    Code   = int.Parse(city),
                    Type   = 1,
                    UserId = CurrentUserInfo.Id
                });

                if (cid == 0)
                {
                    return(Json(new JsonResultModel {
                        Message = "修改居住地区信息失败,!"
                    }));
                }
            }
            if (!string.IsNullOrEmpty(area))
            {
                int aid = await
                          UserPublic.AddUserPosition(new UserPositionVModel
                {
                    Code   = int.Parse(area),
                    Type   = 2,
                    UserId = CurrentUserInfo.Id
                });

                if (aid == 0)
                {
                    return(Json(new JsonResultModel {
                        Message = "修改居住地区信息失败,!"
                    }));
                }
            }

            #endregion
            UsersLogin.RefreshCookieUserInfo(CurrentUserInfo.Id);
            return(Json(new JsonResultModel {
                ResultState = true, Message = "修改成功!"
            }));
        }