public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new YorumluoUser
                {
                    UserName = model.Email,
                    UserCode = model.UserCode,
                    City     = model.City,
                    Email    = model.Email
                };


                var result = await userManager.CreateAsync(user, model.Password);


                if (result.Succeeded)
                {
                    await signInManager.SignInAsync(user, isPersistent : false);

                    return(RedirectToAction("index", "yorums"));
                }


                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            return(View(model));
        }
        public async Task <IActionResult> Details(string id)
        {
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name");
            YorumluoUser user  = _userService.GetById(id);
            var          model = new ProfileViewModel()
            {
                User = user,
            };



            var loggeduser = await _userManager.GetUserAsync(User);


            var userFollows = _userService.GetFollows(loggeduser.Id);

            model.FollowerCount = _context.Follows.Where(y => y.FollowedId == user.Id).Count();
            model.FollowedCount = _context.Follows.Where(y => y.FollowerId == user.Id).Count();

            foreach (var users in userFollows)
            {
                if (userFollows.Any(u => u.FollowedId == user.Id))
                {
                    model.User.IsFollowed = true;
                }
                else
                {
                    model.User.IsFollowed = false;
                }
            }


            return(View(model));
        }
Exemple #3
0
        public YorumluoUser Update(YorumluoUser updatedUser)
        {
            YorumluoUser user = GetAll().FirstOrDefault(user => user.Id == updatedUser.Id);

            if (user != null)
            {
                user.Bio = updatedUser.Bio;
            }
            return(user);
        }
Exemple #4
0
        private async Task LoadAsync(YorumluoUser user)
        {
            var userName = await _userManager.GetUserNameAsync(user);

            var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

            Username = userName;

            Input = new InputModel
            {
                PhoneNumber = phoneNumber
            };
        }
Exemple #5
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new YorumluoUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
        public async Task <IActionResult> Follow(YorumluoUser followed)
        {
            var user = await userManager.GetUserAsync(User);

            Follow follow = new Follow();

            follow.FollowerId = user.Id;
            follow.FollowedId = followed.Id;

            var check = _context.Follows.AsNoTracking().Where(y => y.FollowerId == follow.FollowerId && y.FollowedId == follow.FollowedId).SingleOrDefault();

            if (check != null)
            {
                await _userService.Unfollow(follow);
            }
            else
            {
                await _userService.Follow(follow);
            }


            return(RedirectToAction("Index", "Yorums"));
        }