/// <summary> /// 注册服务 /// </summary> /// <param name="userName">用户名</param> /// <param name="password">密码</param> /// <returns>RegisterStatus类型</returns> public static async Task <RegisterStatus> Register(string userName, string email, string phoneNumber, string password) { UserModel user = new UserModel(); user.userName = userName; user.email = email; user.phoneNumber = phoneNumber; user.password = EncriptHelper.ToMd5(password); try { string jsonContent = JsonHelper.ObjectToJson(user); HttpService http = new HttpService(); HttpResponseMessage response = await http.SendPostRequest(InterfaceUrl.UserAccountUrl, jsonContent); if (response != null) { if (response.StatusCode == HttpStatusCode.Created) { roamdingSettings.Values[Constants.SettingName.Token] = response.Content; roamdingSettings.Values[Constants.SettingName.EmailAddress] = email; roamdingSettings.Values[Constants.SettingName.PhoneNumber] = phoneNumber; return(RegisterStatus.Success); } else if (response.StatusCode == HttpStatusCode.Conflict) { return(RegisterStatus.ConflictUserName); } } } catch { } return(RegisterStatus.Failed); }
/// <summary> /// 登录服务 /// </summary> /// <param name="userName">用户名</param> /// <param name="password">密码</param> /// <returns>登录成功返回true,反之返回false</returns> public static async Task <bool> Login(string userName, string password) { HttpService http = new HttpService(); string response = await http.SendGetRequest(InterfaceUrl.UserLogin(userName)); if (response != string.Empty) { try { JObject jsonObject = JObject.Parse(response); if (EncriptHelper.ToMd5(password) == jsonObject["password"].ToString()) { roamdingSettings.Values[Constants.SettingName.Token] = jsonObject["token"].ToString(); roamdingSettings.Values[Constants.SettingName.EmailAddress] = jsonObject["Email"].ToString(); roamdingSettings.Values[Constants.SettingName.PhoneNumber] = jsonObject["PhoneNumber"].ToString(); return(true); } } catch { } } return(false); }