//处理登录反馈消息 private static void HandleLoginResult(JObject head, byte[] data) { //提取结果包头 ResultHead resultHead = GetResultHead(head); //发起登录完成事件 if (head[AttrNames.Error].ToString() != "") { OnLoginDone?.Invoke(resultHead, null); return; } User user = new User { Name = head[AttrNames.User].ToString(), NickName = head[AttrNames.NickName].ToString(), Motto = head[AttrNames.Motto].ToString(), Group = (UserGroup)Enum.Parse(typeof(UserGroup), head[AttrNames.UGroup].ToString()), Photo = User.DefaultPhoto }; if (int.Parse(head[AttrNames.Photo].ToString()) > 0) { MemoryStream ms = new MemoryStream(data); user.Photo = Image.FromStream(ms); } //用户头像数据 OnLoginDone?.Invoke(resultHead, user); }
private void Login() { if (!CheckUserName(txtUserName.Text.Trim())) { return; } if (!CheckPassword(txtPassword.Password)) { return; } string passwordBase64 = Cryptography.Encrypt(txtPassword.Password); string passwordMd5 = Cryptography.MD5Hash(passwordBase64); var user = DataProvider.Instance.DB.Users.Where(x => x.UserName.Equals(txtUserName.Text) && x.Password.Equals(passwordMd5)).FirstOrDefault(); if (user == null) { // user not found txtError.Text = "Tên đăng nhập hoặc mật khẩu không đúng !"; return; } isLogin = true; this.Close(); if (OnLoginDone != null) { OnLoginDone.Invoke(true, user); } }
void Close_Window(object sender, CancelEventArgs e) { if (!isLogin) { if (OnLoginDone != null) { OnLoginDone.Invoke(false, null); } } }
public async Task <Dictionary <string, List <string> > > Login(LoginCommand loginCommand, ElementRef loginButton) { Dictionary <string, List <string> > _errors = null; await http.Create("/api/account/login", loginButton) .OnBadRequest <Dictionary <string, List <string> > >(errors => _errors = errors) .OnOK(() => { OnLoginDone?.Invoke(this, null); uriHelper.NavigateTo("/"); }) .Post(loginCommand); return(_errors); }