UsernamePassword() public static method

Creates Credentials based on a login with a username and a password.
public static UsernamePassword ( string username, string password, bool createUser ) : Credentials
username string The username of the user.
password string The user's password.
createUser bool true if the user should be created, false otherwise. It is not possible to create a user twice when logging in, so this flag should only be set to true the first time a user logs in.
return Credentials
Ejemplo n.º 1
0
        void btnLogin_Clicked(object sender, System.EventArgs e)
        {
            _credentials = Credentials.UsernamePassword(txt_un.Text, txt_pw.Text, false);

            stk_login.IsVisible = false;
            stk_form.IsVisible  = true;

            if (App.Current.Properties.ContainsKey("username"))
            {
                App.Current.Properties["username"] = txt_un.Text;
            }
            else
            {
                App.Current.Properties.Add("username", txt_un.Text);
            }

            if (App.Current.Properties.ContainsKey("password"))
            {
                App.Current.Properties["password"] = txt_pw.Text;
            }
            else
            {
                App.Current.Properties.Add("password", txt_pw.Text);
            }
        }
Ejemplo n.º 2
0
        private async TTask Login()
        {
            var cts = new CancellationTokenSource();

            cts.CancelAfter(TimeSpan.FromMinutes(1));

            await Do(
                func : async() =>
            {
                Realm.Write(() =>
                {
                    LoginInfo.ServerUrl = LoginInfo.ServerUrl.Replace("http://", string.Empty)
                                          .Replace("https://", string.Empty)
                                          .Replace("realm://", string.Empty)
                                          .Replace("realms://", string.Empty);
                });

                Constants.Server.RealmServerAddress = LoginInfo.ServerUrl;

                var credentials = Credentials.UsernamePassword(LoginInfo.Username, Password, false);
                await User.LoginAsync(credentials, new Uri(Constants.Server.AuthServerUrl));

                CoreMethods.SwitchOutRootNavigation(NavigationContainerNames.MainContainer);
            },
                onError : async ex =>
            {
                await TTask.Delay(500, cts.Token);
                UserDialogs.Instance.Alert("Unable to login!", ex.Message);
                LogException(ex);
            },
                loadingMessage : "Logging in...",
                token : cts.Token
                );
        }
Ejemplo n.º 3
0
        async void btnPerm_Clicked(object sender, System.EventArgs e)
        {
            Credentials creds = Credentials.UsernamePassword("realmroot", "realmroot1234", false);
            User        user  = await User.LoginAsync(creds, new Uri(Constants.AuthUrl));

            var condition = PermissionCondition.Default;
            await user.ApplyPermissionsAsync(condition, Constants.RealmPath + "beer", AccessLevel.Read);
        }
Ejemplo n.º 4
0
        private async Task Initialize()
        {
            InitializeComponent();
            await Task.Yield();

            lbl_status.Text = "Ready...";

            if (App.Current.Properties.ContainsKey("username") && App.Current.Properties.ContainsKey("password"))
            {
                stk_login.IsVisible = false;
                stk_form.IsVisible  = true;
                _credentials        = Credentials.UsernamePassword((string)App.Current.Properties["username"], (string)App.Current.Properties["password"], false);
            }
            else
            {
                stk_login.IsVisible = true;
                stk_form.IsVisible  = false;
            }
        }
Ejemplo n.º 5
0
        private async Task <Realm> OpenRealm()
        {
            try
            {
                _credentials = Credentials.UsernamePassword((string)App.Current.Properties["username"], (string)App.Current.Properties["password"], false);
                User user = await User.LoginAsync(_credentials, new Uri(Constants.AuthUrl));

                var configuration = new FullSyncConfiguration(new Uri(Constants.RealmPath + ddl_realm.SelectedItem.ToString()), user);
                var realm         = Realm.GetInstance(configuration);

                return(realm);
            }
            catch (Exception ex)
            {
                lbl_status.Text = ex.Message;

                // Try again
                return(await OpenRealm());
            }
        }