A class, representing the credentials used for authenticating a User.
Пример #1
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
                );
        }
Пример #2
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);
            }
        }
Пример #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);
        }
        private async Task <Realm> OpenRealm()
        {
            var user = User.Current;

            if (user != null)
            {
                var configuration = new FullSyncConfiguration(new Uri(Constants.RealmPath, UriKind.Relative), user);

                // User has already logged in, so we can just load the existing data in the Realm.
                return(Realm.GetInstance(configuration));
            }

            // When that is called in the page constructor, we need to allow the UI operation
            // to complete before we can display a dialog prompt.
            await Task.Yield();

            var response = await UserDialogs.Instance.PromptAsync(new PromptConfig
            {
                Title         = "Login",
                Message       = "Please enter your nickname",
                OkText        = "Login",
                IsCancellable = false,
            });

            var credentials = Credentials.Nickname(response.Value, isAdmin: true);

            try
            {
                UserDialogs.Instance.ShowLoading("Logging in...");

                user = await User.LoginAsync(credentials, new Uri(Constants.AuthUrl));

                UserDialogs.Instance.ShowLoading("Loading data");

                var configuration = new FullSyncConfiguration(new Uri(Constants.RealmPath, UriKind.Relative), user);

                // First time the user logs in, let's use GetInstanceAsync so we fully download the Realm
                // before letting them interract with the UI.
                var realm = await Realm.GetInstanceAsync(configuration);

                UserDialogs.Instance.HideLoading();

                return(realm);
            }
            catch (Exception ex)
            {
                await UserDialogs.Instance.AlertAsync(new AlertConfig
                {
                    Title   = "An error has occurred",
                    Message = $"An error occurred while trying to open the Realm: {ex.Message}"
                });

                // Try again
                return(await OpenRealm());
            }
        }
Пример #5
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;
            }
        }
Пример #6
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());
            }
        }
Пример #7
0
 /// <summary>
 /// Logs the user in to the Realm Object Server.
 /// </summary>
 /// <param name="credentials">The credentials to use for authentication.</param>
 /// <param name="serverUri">The URI of the server that the user is authenticated against.</param>
 /// <returns>An awaitable Task, that, upon completion, contains the logged in user.</returns>
 public static Task <User> LoginAsync(Credentials credentials, Uri serverUri)
 {
     RealmPCLHelpers.ThrowProxyShouldNeverBeUsed();
     return(null);
 }