public async Task <AccountDTO> SignIn(string email, string password, SignInType type)
        {
            try
            {
                var user = await _userManager.FindByEmailAsync(email);

                var isAuthorize = type switch
                {
                    SignInType.Credentials => await _userManager.CheckPasswordAsync(user, password),
                    SignInType.RefreshToken => user != null,
                    _ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
                };
                if (isAuthorize)
                {
                    var roles = await _userManager.GetRolesAsync(user);

                    return(new AccountDTO {
                        Email = user.Email, Role = roles.First()
                    });
                }
                return(null);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 2
0
        void HandleSignInButton(int buttonID)
        {
            switch (buttonID)
            {
            default:
            case 0:     // Facebook
                m_SignInType = SignInType.Facebook;
                if (OnSignIn != null)
                {
                    OnSignIn(this, null);
                }
                break;

            case 1:     // Google
                m_SignInType = SignInType.Google;
                if (OnSignIn != null)
                {
                    OnSignIn(this, null);
                }
                break;

            case 2:     // Email
                m_Mode = Mode.EmailInput;
                VirtualKeyboard.ShowKeyboard(m_Email);
                SetupAccountStatusMode(m_bEmailCreate);
                break;

            case 3:     // Exit
                if (OnExit != null)
                {
                    OnExit(this, null);
                }
                break;
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            localContext = this;
            base.OnCreate(savedInstanceState);

            if (!Utils.Utils.IsNetworkEnabled(this))
            {
                Utils.Utils.ShowDialog(this, "Internet not available.");
                StartActivity(new Intent(Application.Context, typeof(LoginActivity)));
                Finish();
            }
            else
            {
                if (Intent.Extras != null)
                {
                    foreach (var key in Intent.Extras.KeySet())
                    {
                        if (key.Equals(KEY_SHOW_PAGE))
                        {
                            signInType = (SignInType)Intent.Extras.GetInt(key);
                        }
                    }
                }

                string strLogin = string.Format(B2CConfig.AuthorizeURL, B2CConfig.Tenant, (signInType == SignInType.SIGN_IN ? B2CPolicy.SignInPolicyId : B2CPolicy.SignUpPolicyId), B2CConfig.ClientId, B2CConfig.Redirect_Uri);
                SetContentView(Resource.Layout.LoginNew);
                localWebView = FindViewById <WebView>(Resource.Id.LocalWebView);
                localWebView.SetWebViewClient(new MyWebView()); // stops request going to Web Browser
                localWebView.ClearCache(true);
                localWebView.Settings.JavaScriptEnabled = true;
                localWebView.LoadUrl(strLogin);
            }
        }
Esempio n. 4
0
        public bool UpdateContentSignInType(int generalId, SignInType signInType)
        {
            Parameters cmdParams = new Parameters();

            cmdParams.AddInParameter("@GeneralId", DbType.Int32, generalId);
            cmdParams.AddInParameter("@SigninType", DbType.Int32, signInType);
            return(DBHelper.ExecuteSql("UPDATE PE_CommonModel SET SigninType = @SigninType WHERE GeneralId = @GeneralId", cmdParams));
        }
Esempio n. 5
0
        /// <summary>
        /// Log in an existing user, or login via a third-party provider.
        /// </summary>
        /// <param name="type">Type of Credentials being passed</param>
        /// <param name="identifierOrToken">An email, phone, or RefreshToken</param>
        /// <param name="password">Password to account (optional if `RefreshToken`)</param>
        /// <param name="scopes">A space-separated list of scopes granted to the OAuth application.</param>
        /// <returns></returns>
        public async Task <Session> SignIn(SignInType type, string identifierOrToken, string password = null, string scopes = null)
        {
            await DestroySession();

            try
            {
                Session session = null;
                switch (type)
                {
                case SignInType.Email:
                    session = await api.SignInWithEmail(identifierOrToken, password);

                    break;

                case SignInType.Phone:
                    if (string.IsNullOrEmpty(password))
                    {
                        var response = await api.SendMobileOTP(identifierOrToken);

                        return(null);
                    }
                    else
                    {
                        session = await api.SignInWithPhone(identifierOrToken, password);
                    }
                    break;

                case SignInType.RefreshToken:
                    CurrentSession = new Session();
                    CurrentSession.RefreshToken = identifierOrToken;

                    await RefreshToken();

                    return(CurrentSession);
                }

                if (session?.User?.ConfirmedAt != null)
                {
                    await PersistSession(session);

                    StateChanged?.Invoke(this, new ClientStateChanged(AuthState.SignedIn));
                    return(CurrentSession);
                }

                return(null);
            }
            catch (RequestException ex)
            {
                throw ExceptionHandler.Parse(ex);
            }
        }
Esempio n. 6
0
        void HandleDialogButton(int buttonID)
        {
            switch (buttonID)
            {
            case 0:     // Sign In
                m_SignInType = SignInType.Email;
                if (OnSignIn != null)
                {
                    OnSignIn(this, null);
                }
                break;

            case 1:     // Cancel
                m_Mode = Mode.SignInButtons;
                SetTitle("Sign In");
                break;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Log in an existing user, or login via a third-party provider.
        /// </summary>
        /// <param name="type">Type of Credentials being passed</param>
        /// <param name="identifierOrToken">An email, phone, or RefreshToken</param>
        /// <param name="password">Password to account (optional if `RefreshToken`)</param>
        /// <param name="scopes">A space-separated list of scopes granted to the OAuth application.</param>
        /// <returns></returns>
        public static async Task <Session> SignIn(SignInType type, string identifierOrToken, string password = null, StatelessClientOptions options = null)
        {
            try
            {
                var     api     = GetApi(options);
                Session session = null;
                switch (type)
                {
                case SignInType.Email:
                    session = await api.SignInWithEmail(identifierOrToken, password);

                    break;

                case SignInType.Phone:
                    if (string.IsNullOrEmpty(password))
                    {
                        var response = await api.SendMobileOTP(identifierOrToken);

                        return(null);
                    }
                    else
                    {
                        session = await api.SignInWithPhone(identifierOrToken, password);
                    }
                    break;

                case SignInType.RefreshToken:
                    session = await RefreshToken(identifierOrToken, options);

                    break;
                }

                if (session?.User?.ConfirmedAt != null)
                {
                    return(session);
                }

                return(null);
            }
            catch (RequestException ex)
            {
                throw ExceptionHandler.Parse(ex);
            }
        }
        //------------------------------------------------------------------------------------------------------------------------------------------

        public async Task <AccountDTO> SignIn(string email, string password, SignInType type)
        {
            try
            {
                bool isAuthorize;
                var  user = await _userManager.FindByEmailAsync(email);

                switch (type)
                {
                case SignInType.Credentials:
                    isAuthorize = await _userManager.CheckPasswordAsync(user, password);

                    break;

                case SignInType.RefreshToken:
                    isAuthorize = user != null;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
                }

                if (isAuthorize)
                {
                    var roles = await _userManager.GetRolesAsync(user);

                    return(new AccountDTO {
                        Email = user.Email, Role = roles.First()
                    });
                }
                return(null);
            }
            catch (Exception)
            {
                return(null);
            }
        }
 public static bool UpdateContentSignInType(int generalId, SignInType signInType)
 {
     return(dal.UpdateContentSignInType(generalId, signInType));
 }