public void LoginIn() { string UserName = Request["txt_account"]; //获取输入的用户名 string UserPwd = Request["txt_password"]; //获取输入的密码 BmobUser user = new BmobUser(); BmobWindows bmob = new BmobWindows(); bmob.Login <BmobUser>(UserName, UserPwd, (resp, exception) => { if (exception != null) { Debug.WriteLine("登录失败, 失败原因为: " + exception.Message); return; } Response.Write("<script>window.location.href='https://www.baidu.com/'</script>"); Debug.WriteLine("登录成功, 当前用户对象Session: " + BmobUser.CurrentUser.sessionToken); }); //try //{ // if (UserName == "admin") // return Content(new AjaxResult { state = ResultType.success.ToString(), message = "登录成功。" }.ToJson()); // else if (UserPwd == "123456") // return Content(new AjaxResult { state = ResultType.success.ToString(), message = "登录成功。" }.ToJson()); // else // return Content(new AjaxResult { state = ResultType.error.ToString(), message = "请验证帐号及密码!" }.ToJson()); //} //catch (Exception ex) //{ // return Content(new AjaxResult { state = ResultType.error.ToString(), message = ex.Message }.ToJson()); //} }
public void SignupTest() { BmobUser user = new BmobUser(); user.username = "******"; user.password = "******"; // 1 try { var future = Bmob.SignupTaskAsync(user); FinishedCallback(future.Result, null); } catch (Exception e) { Console.WriteLine(e); } // 2 try { var future = Bmob.SignupTaskAsync(user); FinishedCallback(future.Result, null); } catch (Exception e) { Console.WriteLine(e); } }
public void UpdateUserTest() { var updateData = new BmobUser(); updateData.email = "*****@*****.**"; var future = Bmob.UpdateUserTaskAsync("b0eab87db3", updateData, "58837ed540b2849680523e99b963501b"); FinishedCallback(future.Result, null); }
public void RoleTest() { //这里创建四个用户对象指针,分别为老板、人事小张、出纳小谢和自己 // just for test BmobPointer <BmobUser> boss = new BmobUser() { objectId = "1" }; BmobPointer <BmobUser> hr_zhang = new BmobUser() { objectId = "2" }; BmobPointer <BmobUser> hr_luo = new BmobUser() { objectId = "3" }; BmobPointer <BmobUser> cashier_xie = new BmobUser() { objectId = "4" }; BmobPointer <BmobUser> me = new BmobUser() { objectId = "5" }; { //创建HR和Cashier两个用户角色(这里为了举例BmobRole的使用,将这段代码写在这里,正常情况下放在员工管理界面会更合适) BmobRole hr = new BmobRole(); hr.name = "HR"; var users = new BmobRelation <BmobUser>(); users.Add(hr_zhang); users.Add(hr_luo); //将hr_zhang和hr_luo归属到hr角色中 hr.AddUsers(users); //保存到云端角色表中(web端可以查看Role表) var future = Bmob.CreateTaskAsync(hr); FinishedCallback(future.Result, null); } { BmobRole cashier = new BmobRole(); cashier.name = "Cashier"; var users = new BmobRelation <BmobUser>(); users.Add(cashier_xie); //将cashier_xie归属到cashier角色中 cashier.AddUsers(users); //保存到云端角色表中(web端可以查看Role表) var future = Bmob.CreateTaskAsync(cashier); FinishedCallback(future.Result, null); } }
/// <summary> /// 邮箱验证 /// </summary> /// <param name="email">需要验证的邮箱号</param> /// <param name="callback">验证结果的回调</param> public void EmailVerify(String email, BmobCallback <EmptyCallbackData> callback) { var bia = BmobInteractObject.EmailVerify; bia.Table = "_User"; var user = new BmobUser(); user.email = email; bia.Data = user; submit(bia, callback); }
/// <summary> /// 更新用户信息 /// </summary> /// <param name="objectId">这条用户信息对应的objectId</param> /// <param name="data">需要更新的内容</param> /// <param name="sessionToken">这个用户登录之后获取的sessionToken</param> /// <param name="callback">更新之后的回调</param> public void UpdateUser(String objectId, BmobUser data, String sessionToken, BmobCallback <UpdateCallbackData> callback) { if (Utilities.Empty(sessionToken)) { callback(null, new BmobException("删除用户表数据时,必须先登录获取sessionToken的值!")); return; } var bia = BmobInteractObject.Update; bia.Data = data; bia.Table = "_User"; bia.ObjectId = objectId; bia.SessionToken = sessionToken; submit(bia, callback); }
/// <summary> /// 用户登录 /// /// 返回用户User表改用户的所有字段 /// </summary> /// <typeparam name="T">BmobUser用户类泛型</typeparam> /// <param name="username">用户名</param> /// <param name="pwd">密码</param> /// <param name="callback">用户登录的结果回调</param> public void Login <T>(string username, string pwd, BmobCallback <T> callback) where T : BmobUser { var bia = BmobInteractObject.Login; bia.Table = "_User"; var user = new BmobUser(); user.username = username; user.password = pwd; bia.Data = user; submit <T>(bia, (cu, ex) => { // 记录当前已登录的用户! BmobUser.CurrentUser = cu; callback(cu, ex); }); }
public Task <UpdateCallbackData> UpdateUserTaskAsync(String objectId, BmobUser data, String sessionToken) { return(ExecuteTaskAsync <UpdateCallbackData>(callback => { UpdateUser(objectId, data, sessionToken, callback); }, CancellationToken.None)); }
public Task <BmobUser> SignupTaskAsync(BmobUser user) { return(ExecuteTaskAsync <BmobUser>(callback => { Signup(user, callback); }, CancellationToken.None)); }
/// <summary> /// 使用默认的BmobUser进行注册。即不添加任何额外的字段情况下使用。 /// </summary> public void Signup(BmobUser user, BmobCallback <BmobUser> callback) { this.Signup <BmobUser>(user, callback); }