protected void submit_Click(object sender, EventArgs e) { var md5 = Utility.MD5(password.Value).ToLower(); var name = username.Value.Trim(); name = name.Length >= 30 ? name.Substring(0, 30) : name; using (var bll = new AccountBLL()) { var account = bll.Find(f => f.Code.Equals(name)); if (null != account) { using (var action = new ActionBLL()) { if (!account.Password.ToLower().Equals(md5)) { SaveHistory(new TB_AccountHistory() { Account = account.id, ActionId = action.Find(f => f.Name.Equals("Login")).id, ObjectA = Utility.GetClientBrowser(Request) + ", login fail: password error" }); ShowNotification("../default.aspx", "Login fail: password is not correct.", false); } else if (account.Locked == true) { SaveHistory(new TB_AccountHistory() { Account = account.id, ActionId = action.Find(f => f.Name.Equals("Login")).id, ObjectA = Utility.GetClientBrowser(Request) + ", login blocked: account has locked" }); ShowNotification("../default.aspx", "You cannot login: your account has been locked.", false); } else { SaveHistory(new TB_AccountHistory() { Account = account.id, ActionId = action.Find(f => f.Name.Equals("Login")).id, ObjectA = Utility.GetClientBrowser(Request) }); updateAccount(account); } } } else { ShowNotification("../default.aspx", "Login fail: no account exist like your input.", false); } } }
private void HandleAccountBinder(Api obj) { var acnt = ParseJson <Account>(obj.content); if (null == acnt) { ResponseData(-1, "Can not bind your account with error object."); } else if (string.IsNullOrEmpty(acnt.device)) { ResponseData(-1, "Can not bind your account with error parameter."); } else { var name = acnt.name; if (name.Length >= 30) { name = name.Substring(0, 30); } var pwd = acnt.md5.ToLower(); try { using (var bll = new AccountBLL()) { var account = bll.Find(f => f.Code.Equals(name) && f.Delete == false); if (null == account) { ResponseData(-1, "Your account is not exist"); } else { if (!pwd.Equals(account.Password.ToLower())) { ResponseData(-1, "Your password is not correct."); } else if (account.Locked == true) { ResponseData(-1, "Your account was locked."); } else if ((int?)null != account.Tracker) { if (account.TB_Tracker.DeviceId.Equals(acnt.device)) { string uuid = Guid.NewGuid().ToString(); // 每次绑定账户都生成一个新的session id bll.Update(u => u.id == account.id, act => { act.DeviceLoginId = uuid; act.TB_Tracker.LastActionAt = DateTime.Now; }); // 返回当前已经登录过的用户信息 ResponseData(0, JsonConverter.ToJson(new Account() { name = acnt.name, data = account.TB_Tracker.SimCard, device = account.Belong, // 新的session id session = uuid }), true); } else { ResponseData(-1, "Your account was bind with another device."); } } else { // 创建一个新的tracker绑定关系 BindAccountWithTracker(account, acnt.device, bll); } } } } catch (Exception e) { ResponseData(-1, string.Format("Can not hander your \\\"bind account\\\" request: {0}", e.Message)); } } }