예제 #1
0
        public HttpResponseMessage Post(UserWrap userWrap)
        {
            string errMsg             = "";
            string errMsgForChangeset = "";
            bool   isChangesetError   = false;
            User   model = userWrap.User;

            Model.Changeset changeset = new Model.Changeset();
            try
            {
                string token     = this.ControllerContext.Request.Headers.GetValues("Token").First();
                bool   isChecked = TokenManage.CheckAuthorizer(token, PowerStatusCode.Systemer, out auth, out errMsg);
                if (isChecked)
                {
                    if (tryValidate(model, out errMsg))
                    {
                        if (this.tryPost(ref model, out errMsg))
                        {
                            if (!ChangesetManager.tryFetch(auth.Sync, ref changeset, out errMsgForChangeset))
                            {
                                isChangesetError = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }
            var    status = HttpStatusCode.OK;
            string json   = "";

            if (errMsg.Length > 0)
            {
                status = (HttpStatusCode)422;
                var msg = new { errors = new { ServerSideError = errMsg } };
                json = JsonConvert.SerializeObject(msg);
            }
            else
            {
                status = HttpStatusCode.OK;
                var msg = new { User = model, Changeset = changeset, IsChangesetError = isChangesetError, ErrMsgForChangeset = errMsgForChangeset };
                json = JsonConvert.SerializeObject(msg);
            }
            return(new HttpResponseMessage(status)
            {
                Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
            });
        }
예제 #2
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            string        userName      = user_txt.Text;
            string        password      = password_txt.Text;
            Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            byte[] passwordSalt = Convert.FromBase64String(configuration.AppSettings.Settings["salt"].Value);
            byte[] passwordHash = Convert.FromBase64String(configuration.AppSettings.Settings["hash"].Value);

            bool flag = UserWrap.VerifyPassword(password, passwordSalt, passwordHash);

            if (userName == "admin" && flag)
            {
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                this.DialogResult = DialogResult.None;
                XtraMessageBox.Show("用户名或密码错误!");
                return;
            }
        }