protected override async Task OnInitializedAsync()
        {
            AuthenticateSate = await authenticationStateTask;

            if (AuthenticateSate.User.Identity.IsAuthenticated)
            {
                User = AuthenticateSate.User;
            }

            var uri = Navigation.ToAbsoluteUri(Navigation.Uri);

            var apiUrl = $"/api/ads/{Id}";

            if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("social", out var _social))
            {
                apiUrl += $"?social={_social}";
            }

            var getDetail = await HttpClient.GetAsync(apiUrl);

            getDetail.EnsureSuccessStatusCode();
            var json = await getDetail.Content.ReadAsStringAsync();

            Ad = JsonConvert.DeserializeObject <AdViewModel>(json);

            Author = Ad.Owner;

            await base.OnInitializedAsync();
        }
        protected override async Task OnInitializedAsync()
        {
            var authenticateSate = await authenticationStateTask;

            User = authenticateSate.User;

            ListContact = StateTchatContainer.MyContacts;
            await base.OnInitializedAsync();
        }
        public async Task <IActionResult> Create(ViewApplicationUser vm)
        {
            var user = new AppIdentityUser
            {
                UserName = vm.UserName,
                Email    = vm.Email,
            };
            Guid   gu       = Guid.NewGuid();
            string TempPass = Convert.ToBase64String(gu.ToByteArray());

            TempPass = TempPass.Replace("=", "");
            TempPass = TempPass.Replace("+", "");
            var appUser = new ApplicationUser
            {
                AppIdentityUserId = user.Id,
                FirstName         = vm.FirstName,
                LastName          = vm.LastName,
                Patronymic        = vm.Patronymic,
                Gender            = vm.Gender,
                Age    = vm.Age,
                UniqId = vm.UniqId,
            };
            //if (!user.EmailConfirmed  )
            //{
            //    // Send email confirmation email
            //    var confirmToken = await _userManager.GenerateEmailConfirmationTokenAsync(user);
            //    var emailConfirmUrl = Url.RouteUrl("ConfirmEmail", new { uid = user.Id, token = confirmToken }, this.Request.Scheme);
            //    await _emailSender.SendEmailAsync(user.Email, "Please confirm your account",
            //            $"Please confirm your account by clicking this <a href=\"{emailConfirmUrl}\">link</a>."
            //    );

            //    _logger.LogInformation($"Sent email confirmation email (id: {user.Id})");
            //}
            IdentityResult result = await _userManager.CreateAsync(user, TempPass);

            await _userManager.AddToRolesAsync(user, vm.Roles);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors));
            }

            var profile = await _ctx.AppUsers.AddAsync(appUser);

            await _ctx.SaveChangesAsync();

            return(Ok());
        }
Beispiel #4
0
        public async Task ChangeEmail()
        {
            SecurityEmailChange viewModel = new()
            {
                NewEmail        = "*****@*****.**",
                ApplicationUser = new ViewApplicationUser
                {
                    Id    = Context.ApplicationUser.FirstOrDefault(x => x.Email == "*****@*****.**").Id,
                    Email = Context.ApplicationUser.FirstOrDefault(x => x.Email == "*****@*****.**").Email
                }
            };

            await Service.ChangeEmail(viewModel);

            Assert.Pass();
        }
    }
Beispiel #5
0
        public void ChangePassword()
        {
            SecurityPasswordChange viewModel = new()
            {
                CurrentPassword = "******",
                NewPassword     = "******",
                ApplicationUser = new ViewApplicationUser
                {
                    Id    = Context.ApplicationUser.FirstOrDefault(x => x.Email == "*****@*****.**").Id,
                    Email = Context.ApplicationUser.FirstOrDefault(x => x.Email == "*****@*****.**").Email
                }
            };

            Exception exception = Assert.ThrowsAsync <Exception>(async() => await Service.ChangePassword(viewModel));

            Assert.Pass();
        }
        public async Task <IActionResult> Edit(string id, [FromBody] ViewApplicationUser vm)
        {
            var currentIdentity = _repo.GetIdentity(id);

            if (currentIdentity == null)
            {
                var error = new { StatusText = "There is no item with this id" };
                return(BadRequest(error));
            }

            var differencesIdentity = vm.DiffUpdateProperties(currentIdentity);
            var differencesProfile  = vm.CreateExampleFromDifference(currentIdentity.AppUser);

            IList <string> roles = await _userManager.GetRolesAsync(currentIdentity);

            List <string> arrayToAction = new List <string>();

            if (roles.Count < vm.Roles.Count)
            {
                for (int i = 0; i < vm.Roles.Count; i++)
                {
                    if (!roles.Contains(vm.Roles[i]))
                    {
                        arrayToAction.Add(vm.Roles[i]);
                    }
                }
                await _userManager.AddToRolesAsync(currentIdentity, arrayToAction);
            }
            else if (roles.Count > vm.Roles.Count)
            {
                for (int i = 0; i < roles.Count; i++)
                {
                    if (!vm.Roles.Contains(roles[i]))
                    {
                        arrayToAction.Add(vm.Roles[i]);
                    }
                }
                await _userManager.RemoveFromRolesAsync(currentIdentity
                                                        , arrayToAction);
            }
            _repo.UpdateProfile(differencesProfile);
            _repo.UpdateIdentity(differencesIdentity);
            await _repo.SaveChangesAsync();

            return(Ok());
        }
Beispiel #7
0
        public void AddArchiveVersion()
        {
            AddArchive @addArchive = new()
            {
                ApplicationUsersId = Context.ApplicationUser.ToList().Select(x => x.Id).ToList(),
                Data = new byte[10],
                Name = "sixtharchive.txt",
                Size = 1024,
                Type = "Text",
                By   = new ViewApplicationUser()
                {
                    Id    = Context.ApplicationUser.FirstOrDefault().Id,
                    Email = Context.ApplicationUser.FirstOrDefault().Email
                }
            };

            Service.AddArchiveVersion(@addArchive, Context.Archive.FirstOrDefault());

            Assert.Pass();
        }
Beispiel #8
0
        public async Task AddArchive()
        {
            AddArchive @addArchive = new()
            {
                ApplicationUsersId = Context.ApplicationUser.ToList().Select(x => x.Id).ToList(),
                Data = new byte[10],
                Name = "foutharchive.txt",
                Size = 1024,
                Type = "Text",
                By   = new ViewApplicationUser()
                {
                    Id    = Context.ApplicationUser.FirstOrDefault().Id,
                    Email = Context.ApplicationUser.FirstOrDefault().Email
                }
            };

            await Service.AddArchive(@addArchive);

            Assert.Pass();
        }
        protected override async Task OnInitializedAsync()
        {
            await jSRuntime.InvokeVoidAsync("outsideClickHandler", "dropdownmenu", DotNetObjectReference.Create(this));

            AuthenticateSate = await authenticationStateTask;

            if (AuthenticateSate.User.Identity.IsAuthenticated)
            {
                User = AuthenticateSate.User;
            }

            var getAds = await HttpClient.GetAsync("/api/Ads");

            getAds.EnsureSuccessStatusCode();
            var json = await getAds.Content.ReadAsStringAsync();

            RefAds = JsonConvert.DeserializeObject <MyAdsViewModel>(json);
            AdsTmp = RefAds.Ads.Where(a => a.OwnerId == User.Id).ToList();
            await base.OnInitializedAsync();
        }
Beispiel #10
0
        public void UpdateApplicationUserArchive()
        {
            UpdateArchive @updateArchive = new()
            {
                Id = Context.Archive.FirstOrDefault().Id,
                ApplicationUsersId = Context.ApplicationUser.ToList().Select(x => x.Id).ToList(),
                Data = new byte[10],
                Name = Context.Archive.FirstOrDefault().Name,
                Size = 1024,
                Type = "Text",
                By   = new ViewApplicationUser()
                {
                    Id    = Context.ApplicationUser.FirstOrDefault().Id,
                    Email = Context.ApplicationUser.FirstOrDefault().Email
                }
            };

            Service.UpdateApplicationUserArchive(@updateArchive, Context.Archive.FirstOrDefault());

            Assert.Pass();
        }
Beispiel #11
0
        public void CheckName()
        {
            UpdateArchive @updateArchive = new()
            {
                Id = Context.Archive.FirstOrDefault().Id,
                ApplicationUsersId = Context.ApplicationUser.ToList().Select(x => x.Id).ToList(),
                Data = new byte[10],
                Name = Context.Archive.FirstOrDefault().Name,
                Size = 1024,
                Type = "Text",
                By   = new ViewApplicationUser()
                {
                    Id    = Context.ApplicationUser.FirstOrDefault().Id,
                    Email = Context.ApplicationUser.FirstOrDefault().Email
                }
            };

            Exception exception = Assert.ThrowsAsync <Exception>(async() => await Service.CheckName(@updateArchive));

            Assert.Pass();
        }
    }
        public async Task <ActionResult <ApplicationUser> > UpdateUser(ViewApplicationUser applicationUser)
        {
            var user = await _userManager.FindByIdAsync(applicationUser.Id);

            user.Title                 = applicationUser.Title;
            user.Address               = applicationUser.Address;
            user.City                  = applicationUser.City;
            user.Country               = applicationUser.Country;
            user.DisplayDescription    = applicationUser.DisplayDescription;
            user.DescriptionVideo      = applicationUser.DescriptionVideo;
            user.DescriptionVideoCover = applicationUser.DescriptionVideoCover;
            user.Description           = applicationUser.Description;
            user.PinDigit              = applicationUser.DigitCode;
            user.PinCode               = applicationUser.PinCode;
            user.DisplayName           = applicationUser.DisplayName;
            user.FirstName             = applicationUser.FirstName;
            user.PhoneNumber           = applicationUser.PhoneNumber;
            user.IsAdmin               = applicationUser.IsAdmin;
            user.IsManager             = applicationUser.IsManager;
            user.IsOnline              = applicationUser.IsOnline;
            user.IsOperator            = applicationUser.IsOperator;
            user.LastLogin             = applicationUser.LastLogin;
            user.LastName              = applicationUser.LastName;
            user.NubmerOfView          = applicationUser.NumberOfView;
            user.PhotoUrl              = applicationUser.PhotoUrl;
            user.VideoProfileUrl       = applicationUser.VideoProfileUrl;
            user.VideProfileCoverUrl   = applicationUser.VideProfileCoverUrl;
            user.SubscriptionStartDate = user.SubscriptionStartDate;
            user.SubscriptionEndDate   = user.SubscriptionEndDate;

            var result = await _userManager.UpdateAsync(user);

            if (result.Succeeded)
            {
                return(Ok(applicationUser));
            }

            return(BadRequest());
        }
        public async Task <ViewApplicationUser> GetUser(string id)
        {
            var user = _repo.GetProfile(id);

            var valueUser = new ViewApplicationUser
            {
                Id         = user.ApplicationUserId,
                UserName   = user.IdentityOfUser.UserName,
                FirstName  = user.FirstName,
                LastName   = user.LastName,
                Patronymic = user.Patronymic,
                Gender     = user.Gender,
                UniqId     = user.UniqId,
                Age        = user.Age,
                Email      = user.IdentityOfUser.Email,
                Belongings = user.Belongings
            };

            IList <string> res = await _userManager.GetRolesAsync(user.IdentityOfUser);

            valueUser.Roles = res.ToArray();
            return(valueUser);
        }
Beispiel #14
0
 public void SetManager(ViewApplicationUser manager)
 {
     Manager   = manager;
     ManagerId = manager.Id;
 }