示例#1
0
        public JsonResponse SingUp([FromBody] UserInfo model)
        {
            if (model.Email == null || model.Password == null || model.Nickname == null)
            {
                return(BadResponse("参数提供不完整"));
            }
            //检查邮箱是否可用
            JsonResponse emailModel = CheckUser(model.Email);

            if (!emailModel.Success)
            {
                return(BadResponse(emailModel.Message));
            }
            //检查昵称是否可用
            JsonResponse nicknameModel = CheckUser(model.Email);

            if (!nicknameModel.Success)
            {
                return(BadResponse(nicknameModel.Message));
            }
            //密码加密
            model.Password = PasswordHelper.PwdStrToHashStr(model.Password);
            //写入数据库
            if (UserInfoBll.Insert(model))
            {
                return(OkResponse(null));
            }
            else
            {
                return(BadResponse("注册失败,请重试"));
            }
        }
示例#2
0
        //保存
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string      id           = Request["UserId"];
            UserInfoBll bll          = new UserInfoBll();
            UserInfo    model        = new UserInfo();
            string      oldAdminName = string.Empty;

            if (!string.IsNullOrEmpty(id))//如果是修改操作
            {
                model = bll.GetModel(Convert.ToInt32(id));
            }
            else //如果是新增操作
            {
                model.UserPwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtUserPwd.Text.Trim(), "MD5");
            }
            model.UserName = this.txtUserName.Text.Trim();
            model.RoleId   = "";
            for (int i = 0; i < this.chkListRole.Items.Count; i++)
            {
                if (this.chkListRole.Items[i].Selected)
                {
                    model.RoleId += this.chkListRole.Items[i].Value + ",";
                }
            }
            if (model.RoleId.IndexOf(',') != -1)
            {
                model.RoleId = model.RoleId.Substring(0, model.RoleId.Length - 1);
            }
            if (string.IsNullOrEmpty(model.RoleId))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请选择一个角色!');</script>");
                return;
            }
            model.IsLock = Convert.ToInt32(this.rdoList.SelectedValue);
            model.Desc   = this.txtDesc.Text.Trim();


            int n = 0;

            if (!string.IsNullOrEmpty(id))//如果是修改操作
            {
                n = bll.Update(model, null);
            }
            else //如果是新增操作
            {
                n = bll.Insert(model, null);
            }

            if (n > 0)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存成功!');</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存失败!');</script>");
            }
        }