Exemplo n.º 1
0
        public async Task <bool> LoginAsync(string username, string password)
        {
            try
            {
                _act_client = Create <AccountClient>();
                var apiResultOfLoginResult = await _act_client.LoginAsync(new LoginDto()
                {
                    UserName = username, Password = password
                });

                if (apiResultOfLoginResult.Code == (int)ApiCode.Success)
                {
                    _result = apiResultOfLoginResult.Data;
                    HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {Token.Access_token}");
                    ApiResultOfUserInfoDto userInfoDto = await _act_client.MyInfoAsync();

                    MyInfo = userInfoDto.Data;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Login error ", ex);
            }
            return((bool)(_result?.SignIn.Succeeded));
        }
Exemplo n.º 2
0
        public static async Task <Session> LoginAsync(this AccountClient client, string username, string password)
        {
            Session = (await client.LoginAsync(new LoginDto()
            {
                UserName = username, Password = password
            })).Data;
            var token = Session.Token;

            HttpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token.Access_token);
            ApiResultOfUserInfoDto userInfoDto = await client.MyInfoAsync();

            MyInfo = userInfoDto.Data;
            return(Session);
        }
Exemplo n.º 3
0
        public static async Task <Session> LoginAsync(this AccountClient client, string username, string password)
        {
            Session = await client.LoginAsync(new LoginDto()
            {
                UserName = username, Password = password
            });

            var token = Session.Token;

            HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.Access_token}");
            ApiResultOfUserInfoDto userInfoDto = await client.MyInfoAsync();

            MyInfo = userInfoDto.Data;
            return(Session);
        }
Exemplo n.º 4
0
        public async Task <bool> RegisterAsync(string customer, string username, string password, string phoneNumber)
        {
            try
            {
                _act_client = Create <AccountClient>();
                _result     = await _act_client.RegisterAsync(new RegisterDto()
                {
                    Customer = customer, Email = username, Password = password, PhoneNumber = phoneNumber
                });

                HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {Token.Access_token}");
                ApiResultOfUserInfoDto userInfoDto = await _act_client.MyInfoAsync();

                MyInfo = userInfoDto.Data;
            }
            catch (Exception ex)
            {
                throw new Exception("Register error ", ex);
            }
            return((bool)(_result?.SignIn.Succeeded));
        }