Exemplo n.º 1
0
        //JsonElement
        public JsonDocument Authenticate([FromBody] LoginCredentials user)
        {
            if (user.email == null || user.password == null)
            {
                throwError("შეიყვანეთ მონაცემები");
            }
            var method = new PKG_USERS();

            //AuthUser authUser = null;
            try
            {
                authUser = new TokenManager().getAuthUserByToken(null, HttpContext);
            }
            catch (Exception ex)
            {
            }

            // if anyone is logged in
            if (authUser != null)
            {
                return(throwError("You are already logged in as " + authUser));
            }
            AuthUser auth = null;

            //if no one is logged in, Authenticate
            if (method.Authenticate(user.email.ToString(), user.password.ToString(), out auth))
            {
                authUser       = auth;
                authUser.token = new TokenManager().createSetToken(authUser);
                var dict = new Dictionary <string, object>();
                dict.Add("access_token", authUser.token);
                return(Success(dict));
            }
            else
            {
                return(throwError("ელ.ფოსტა ან პაროლი არასწორია"));
            }
        }
Exemplo n.º 2
0
        //JsonElement
        public JsonDocument Authenticate([FromBody] UserCredentials user)
        {
            var method = new PKG_USERS();

            //AuthUser authUser = null;
            try
            {
                authUser = new TokenManager().getAuthUserByToken(null, HttpContext);
            }
            catch (Exception ex)
            {
            }

            // if anyone is logged in
            if (authUser != null)
            {
                return(throwError("You are already logged in as " + authUser));
            }
            AuthUser auth = null;

            //if no one is logged in, Authenticate
            if (method.Authenticate(user.email.ToString(), user.password.ToString(), out auth))
            {
                authUser = auth;
                try
                {
                    authUser.user1C = new PKG_1C().get1CUser(authUser.ID);
                }
                catch (Exception ex)
                {
                }
                authUser.token = new TokenManager().createSetToken(authUser);
                var dict = new Dictionary <string, object>();
                dict.Add("access_token", authUser.token);

                JsonDocument bxAuth = null;

                bxAuth = AuthBitrixFromAuthUser(authUser); // Auths bitrix user from authUser refreshtoken or email pass

                if (bxAuth == null)
                {
                    return(Success(dict));
                }

                JsonElement bxToken;
                JsonElement bxRefreshToken;
                bxAuth.RootElement.TryGetProperty("access_token", out bxToken);
                // Get Bitrix and your accesstoken together and return
                if (bxToken.ToString().Length > 0)
                {
                    authUser.bx_access_token = bxToken.ToString();
                }

                var bxData = new Dictionary <string, object>();
                bxData.Add("access_token", bxToken);
                dict.Add("bx_data", bxData);

                return(Success(dict));
            }
            else
            {
                return(throwError("ელ.ფოსტა ან პაროლი არასწორია"));
            }
        }