示例#1
0
		public async Task<AuthResponse> authenticate (string userName, string userPassword, string pin)
		{
			AuthResponse authresponse = new AuthResponse ();

			String path = string.Format (@"https://www.pengeplan.dk/api/user/authenticate/{0}", userName);
			var request = (HttpWebRequest)WebRequest.Create (path);
			request.ContentType = "application/json";
			request.Method = "GET";
			setBasicAuthHeader (request, userName, userPassword);

			try {
				using (HttpWebResponse response = request.GetResponse () as HttpWebResponse) {
					if (response.StatusCode == HttpStatusCode.OK) {
						using (StreamReader reader = new StreamReader (response.GetResponseStream ())) {
							var content = reader.ReadToEnd ();

							authresponse = JsonConvert.DeserializeObject<AuthResponse> (content);
							authresponse.username = userName;
							authresponse.password = userPassword;
							authresponse.pin = pin;
						}
					} 
				}
			} catch (WebException ex) {
				authresponse.ex = ex;
			}
			return authresponse;
		}
示例#2
0
 public AuthResponse UserInfo()
 {
     IEnumerable<Account> accounts = accountStore.FindAccountsForService (CREDENTIALS_SERVICE);
     Account account = accounts.FirstOrDefault ();
     string username = account.Username;
     string password = account.Properties [LoginService.PASSWORD];
     AuthResponse response = new AuthResponse ();
     response.username = username;
     response.password = password;
     return response;
 }
示例#3
0
 public void StoreCredentials(AuthResponse authResponse)
 {
     DeleteCredentials ();
     Dictionary<string, string> dic = new Dictionary<string, string> ();
     dic.Add (PASSWORD, authResponse.password);
     if (authResponse.pin.Length >= PIN_MIN_LENGTH) {
         dic.Add (PIN, authResponse.pin);
     }
     Account account = new Account (authResponse.username, dic, null);
     accountStore.Save (account, CREDENTIALS_SERVICE);
 }
		public async Task<bool> Login ()
		{
			AuthResponse response = new AuthResponse ();
			if (string.IsNullOrEmpty (Username))
				throw new Exception ("Username is blank.");
			if (string.IsNullOrEmpty (Password))
				throw new Exception ("Password is blank.");
			if (Remember && (string.IsNullOrEmpty (Pin) || Pin.Length < LoginService.PIN_MIN_LENGTH))
				throw new Exception ("Pin is blank or to small.");

			IsBusy = true;
			try {
				response = await pengeplanApi.authenticate (Username, Password, Pin);
				if (response.authorized)
					loginService.StoreCredentials (response);
			} finally {
				IsBusy = false;
			}
			return response.authorized;
		}