Example #1
0
        public async override Task <bool> Login(string username, string password)
        {
            try
            {
                var user = new OwnerAccountModel(username, password);

                _tokenAuth = await Policy.Handle <Exception>(_ => true)
                             .WaitAndRetryAsync
                             (
                    3,
                    sleepDurationProvider: retry => TimeSpan.FromSeconds(5)
                             )
                             .ExecuteAsync(async() => await this._userController.AuthorizationOwner(user));

                if (_tokenAuth.access_token != null)
                {
                    var isUpdate = await this.UpdateProfile();

                    return(isUpdate ? IsAuthenticated = true : IsAuthenticated);
                }
                else
                {
                    return(IsAuthenticated);
                }
            }
            catch (ArgumentException argex)
            {
                ErrorMessage    = argex.Message;
                IsAuthenticated = false;

                return(IsAuthenticated);
            }
        }
Example #2
0
        public static IEnumerable <OwnerAccountModel> ToModels(this OwnerPremiseSet source, string contractAccountId)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var premises = new List <OwnerAccountModel>();

            foreach (var premiseProperty in source.OwnerPremiseProperty.Results)
            {
                var occupiedDate = premiseProperty.Occupiedsince ?? premiseProperty.Lastoccupied;

                var model = new OwnerAccountModel
                {
                    ServiceAddress        = source.PremiseAddress.McfToCassandraModel(),
                    ContractAccountNumber = contractAccountId,
                    OccupiedStatus        = premiseProperty.Occupiedstatus,
                };
                if (occupiedDate.HasValue)
                {
                    model.StatusDate = occupiedDate.Value.ToString("d", CultureInfo.InvariantCulture);
                }

                premises.Add(model);
            }

            return(premises);
        }
Example #3
0
        public async Task <AccessTokenAuthorise> AuthorizationOwner(OwnerAccountModel user)
        {
            var url  = $"{AppData.Identity}/connect/token";
            var data = $"username={user.EMail}&password={user.Password}&grant_type=password&scope=api";

            List <KeyValuePair <string, IEnumerable <string> > > headers = new List <KeyValuePair <string, IEnumerable <string> > >();

            headers.Add(
                new KeyValuePair <string, IEnumerable <string> >(
                    "Authorization",
                    new List <string>()
            {
                "Basic Y2hpZWY6c2VjcmV0"
            }
                    )
                );
            var owner = await ConnectionService.PostAsync <AccessTokenAuthorise>(url
                                                                                 , new StringContent(data, Encoding.UTF8, "application/x-www-form-urlencoded")
                                                                                 , headers, "Не удалось авторизоваться");

            return(owner);
        }
Example #4
0
 public async Task <AccessTokenAuthorise> AuthorizationOwner(OwnerAccountModel user) => await _userService.AuthorizationOwner(user);