/// <summary> /// 修改密码 /// </summary> /// <param name="option"></param> /// <returns></returns> protected internal string ChangePassword(Option option) { if (ownerToken == "" || ownerToken == null) { throw new AuthingException("can not find ownerToken,please login again"); } option.CheckByKeys(new string[] { "email", "client", "verifyCode", "password" }); string query = "mutation changePassword(\n" + " $email: String!,\n" + " $client: String!,\n" + " $password: String!,\n" + " $verifyCode: String!\n" + "){\n" + " changePassword(\n" + " email: $email,\n" + " client: $client,\n" + " password: $password,\n" + " verifyCode: $verifyCode\n" + " ) {\n" + " _id\n" + " email\n" + " emailVerified\n" + " username\n" + " nickname\n" + " company\n" + " photo\n" + " browser\n" + " registerInClient\n" + " registerMethod\n" + " oauth\n" + " token\n" + " tokenExpiredAt\n" + " loginsCount\n" + " lastLogin\n" + " lastIP\n" + " signedUp\n" + " blocked\n" + " isDeleted\n" + " }\n" + "}"; string password = (string)option.GetBykey("password"); try { password = RSAHelper.EncryptWithPublicKey(publicKey, Encoding.UTF8.GetBytes(password)); option.UpdateValue("password", password); } catch (Exception ex) { throw new AuthingException("encrypt password fail", ex); } PostEntity postEntity = new PostEntity(query, option); Dictionary <HttpRequestHeader, string> headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.Authorization, "Bearer " + ownerToken); //"Authorization" string resJson = HttpClientHelper.DoPost(usersUrl, postEntity, headers); return(resJson); }
/// <summary> /// 登录 /// </summary> /// <param name="option"></param> /// <returns></returns> protected internal string Login(Option option) { option.CheckByKeys(new string[] { "registerInClient", "email", "password" }); string query = "mutation login($unionid: String, $email: String, $password: String, $lastIP: String, $registerInClient: String!, $verifyCode: String) {\n" + " login(unionid: $unionid, email: $email, password: $password, lastIP: $lastIP, registerInClient: $registerInClient, verifyCode: $verifyCode) {\n" + " _id\n" + " email\n" + " emailVerified\n" + " username\n" + " nickname\n" + " company\n" + " photo\n" + " browser\n" + " token\n" + " tokenExpiredAt\n" + " loginsCount\n" + " lastLogin\n" + " lastIP\n" + " signedUp\n" + " blocked\n" + " isDeleted\n" + " }\n" + "}"; string password = (string)option.GetBykey("password"); try { password = RSAHelper.EncryptWithPublicKey(publicKey, Encoding.UTF8.GetBytes(password)); option.UpdateValue("password", password); } catch (Exception ex) { throw new AuthingException("encrypt password fail", ex); } PostEntity postEntity = new PostEntity(query, option); string resJson = HttpClientHelper.DoPost(usersUrl, postEntity, null); var jobj = JObject.Parse(resJson); if (jobj["data"] != null && jobj["data"]["login"] != null) { userToken = jobj["data"]["login"]["token"].ToString(); } return(resJson); }
/// <summary> /// 注册用户 /// </summary> /// <param name="option"></param> /// <returns></returns> protected internal string Register(Option option) { option.CheckByKeys(new string[] { "registerInClient", "email", "password" }); string query = " mutation register(\n" + " $unionid: String,\n" + " $email: String, \n" + " $password: String, \n" + " $lastIP: String, \n" + " $forceLogin: Boolean,\n" + " $registerInClient: String!,\n" + " $oauth: String,\n" + " $username: String,\n" + " $nickname: String,\n" + " $registerMethod: String,\n" + " $photo: String\n" + ") {\n" + " register(userInfo: {\n" + " unionid: $unionid,\n" + " email: $email,\n" + " password: $password,\n" + " lastIP: $lastIP,\n" + " forceLogin: $forceLogin,\n" + " registerInClient: $registerInClient,\n" + " oauth: $oauth,\n" + " registerMethod: $registerMethod,\n" + " photo: $photo,\n" + " username: $username,\n" + " nickname: $nickname\n" + " }) {\n" + " _id,\n" + " email,\n" + " emailVerified,\n" + " username,\n" + " nickname,\n" + " company,\n" + " photo,\n" + " browser,\n" + " password,\n" + " token,\n" + " group {\n" + " name\n" + " },\n" + " blocked\n" + " }\n" + "}"; string password = (string)option.GetBykey("password"); try { password = RSAHelper.EncryptWithPublicKey(publicKey, Encoding.UTF8.GetBytes(password)); option.UpdateValue("password", password); } catch (Exception ex) { throw new AuthingException("encrypt password fail", ex); } PostEntity postField = new PostEntity(query, option); string resJson = HttpClientHelper.DoPost(usersUrl, postField, null); return(resJson); }