private async Task<User> LoginUserAsync(string username, string password)
        {
            var parameters = new Dictionary<string, string>
            {
                {"username", username},
                {"password", password}
            };

            try
            {
                DialogService.ShowLoading("Logging you In...");
                var result = (await Client.PostApiAsync("login", parameters)).AsDictionary();
                var user = new User()
                {
                    AuthToken = result[0]["token"],
                    UserId = result[0]["id"],
                    Username = result[0]["username"]
                };

                Client.AuthenticateUser(user);
                return user;
            }
            catch (ApiExecutionException)
            {
                throw new LoginException("Invalid Username or Password. Please try again");
            }
            finally
            {
                DialogService.HideLoading();
            }
        }
 public void AuthenticateUser(User user)
 {
     CurrentUser = new MobileServiceUser(user.UserId)
     {
         MobileServiceAuthenticationToken = user.AuthToken
     };
 }
        private async Task<User> CreateUserAsync(string username, string password)
        {
            var parameters = new Dictionary<string, string>
            {
                { "username", username },
                { "password", password }
            };

            try
            {
                DialogService.ShowLoading("Creating User...");
                var result = (await Client.PostApiAsync("create_user", parameters)).AsDictionary();
                var user = new User()
                {
                    AuthToken = result[0]["token"],
                    UserId = result[0]["id"],
                    Username = result[0]["username"]
                };

                Client.AuthenticateUser(user);
                return user;
            }
            catch (DuplicateDataException)
            {
                throw new CreateUserException("Duplicate User exists. Please try a different username");
            }
            finally
            {
                DialogService.HideLoading();
            }
        }
        public void SaveUser(User user)
        {
            var defaults = NSUserDefaults.StandardUserDefaults;
            defaults[TouchConstants.UserIdKey] = new NSString(EncryptionService.Encrypt(user.UserId));
            defaults[TouchConstants.TokenKey] = new NSString(EncryptionService.Encrypt(user.AuthToken));
            defaults[TouchConstants.UsernameKey] = new NSString(user.Username);

            defaults.Synchronize();
        }
 public void SaveUser(User user)
 {
     var editor = PreferenceManager.GetDefaultSharedPreferences(Forms.Context).Edit();
     editor.PutString(AndroidConstants.SharedPrefsUserIdKey, 
         EncryptionService.Encrypt(user.UserId));
     editor.PutString(AndroidConstants.SharedPrefsTokenKey,
         EncryptionService.Encrypt(user.AuthToken));
     editor.PutString(AndroidConstants.SharedPrefsUsernameKey,
         user.Username);
     editor.Commit();
 }
        public void SaveUser(User user)
        {
            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
            if (!settings.Contains(PhoneConstants.SettingsUserIdKey))
                settings.Add(PhoneConstants.SettingsUserIdKey, string.Empty);
            settings[PhoneConstants.SettingsUserIdKey] = EncryptionService.Encrypt(user.UserId);

            if (!settings.Contains(PhoneConstants.SettingsTokenKey))
                settings.Add(PhoneConstants.SettingsTokenKey, string.Empty);
            settings[PhoneConstants.SettingsTokenKey] = EncryptionService.Encrypt(user.AuthToken);

            if (!settings.Contains(PhoneConstants.SettingsUsernameKey))
                settings.Add(PhoneConstants.SettingsUsernameKey, string.Empty);
            settings[PhoneConstants.SettingsUsernameKey] = user.Username;
            settings.Save();
        }
 public void SetUser(User user)
 {
     Client.AuthenticateUser(user);
 }
 public EnterUsernamePage(User user)
 {
     InitializeComponent();
     _theUser = user;
 }