示例#1
0
		/// <summary>
		/// Logins the async.
		/// </summary>
		/// <returns>String</returns>
		/// <param name="loginViewModel">Login view model.</param>
		public async Task<User> LoginAsync (LoginViewModel loginViewModel)
		{
			client = clientFactory.CreateHttpClient ();

			HttpContent requestBody = new StringContent (string.Format ("grant_type=password&username={0}&password={1}", loginViewModel.Email, loginViewModel.Password));

			HttpResponseMessage response = await client.PostAsync("Token", requestBody);
			if (response.IsSuccessStatusCode) {
				string jsonMessage;
				using (Stream responseStream = await response.Content.ReadAsStreamAsync ()) {
					jsonMessage = new StreamReader (responseStream).ReadToEnd ();
				}

				tokenResponse = (TokenModel)JsonConvert.DeserializeObject (jsonMessage, typeof(TokenModel));
				User user = new User ();
				user = await GetUserByUserName(loginViewModel.Email);
				user.UserAccessToken = tokenResponse;
				return user;
			} else {
				return null;
			}
		}
示例#2
0
		public async Task<User> UpdateAsync (User user)
		{
			//Does not work. There is a security stamp field in the database that gets out of sync when using the UsersRepository to make these updates. Look at UserManager instead
			HttpClientFactory factory = new HttpClientFactory(user.UserAccessToken);
			client = factory.CreateHttpClient ();

			string userJson = JsonConvert.SerializeObject (user);
			HttpContent content = new StringContent (userJson, Encoding.UTF8, "application/json");
			HttpResponseMessage response = await client.PutAsync ("api/account/update/", content);

			if (response.IsSuccessStatusCode) {
				string jsonMessage;
				using (Stream responseStream = await response.Content.ReadAsStreamAsync ()) {
					jsonMessage = new StreamReader (responseStream).ReadToEnd ();
				}

				user = (User)JsonConvert.DeserializeObject (jsonMessage, typeof(User));
				return user;
			} else {
				return null;
			}

		}
 public BaseViewController(IntPtr handle)
     : base(handle)
 {
     CurrentUser = new User ();
 }