示例#1
0
		public async Task Login(string email, string password)
		{
			if (email == null)
				throw new ArgumentNullException("email");

			if (password == null)
				throw new ArgumentNullException("password");

			WebResult response = await Web.POST(DiscordEndpoint.Login, new JsonObject()
			{
				{ "email", JsonValue.CreateStringValue(email) },
				{ "password", JsonValue.CreateStringValue(password) }
			}.Stringify());

			JObject jmessage = JObject.Parse((string)response.Data);

			if (response.Status != System.Net.HttpStatusCode.OK)
			{
				string mailError = jmessage["email"].HasValues ? jmessage["email"][0].ToString() : null;
				string passError = jmessage["password"].HasValues ? jmessage["password"][0].ToString() : null;

				OnLoggedIn(new LoginEventArgs { EmailError = mailError, PasswordError = passError });
				return;
			}

			_isLoggedIn = true;
			_token = jmessage["token"].ToString();
			_account = await GetAccountInfo();

			OnLoggedIn(new LoginEventArgs { Token = _token });
		}
示例#2
0
		public async Task Login(string token)
		{
			if (token == null)
				throw new ArgumentNullException("token");

			WebResult response = await Web.GET(DiscordEndpoint.Users.Replace("{id}", "@me"), token);

			if (response.Status == System.Net.HttpStatusCode.OK)
			{
				_isLoggedIn = true;
				_token = token;
				_account = await GetAccountInfo();

				OnLoggedIn(new LoginEventArgs { Token = _token });
			}
			else
			{
				OnLoggedIn(new LoginEventArgs { IsTokenInvalid = true });
			}
		}