Ejemplo n.º 1
0
        public async Task <UserStatsViewModel> GetUserInfo()
        {
            if (User.Identity.IsAuthenticated)
            {
                string userId = User.Identity.GetResolvedUserId();

                ApplicationUser user = _dbContext.Users.Include(u => u.MemberOf).FirstOrDefault(e => e.Id == userId);
                if (user == null)
                {
                    Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType);
                    return(null);
                }

                UserStatsViewModel model = new UserStatsViewModel(user, true);
                if (user.SteamID != null && string.IsNullOrEmpty(user.AvatarFull))
                {
                    model = await SteamServiceProvider.GetSteamUserDetails(user.SteamID).ConfigureAwait(false);

                    model.SetUser(user);
                }
                model.externalLogins = UserManager.GetLogins(user.Id).Select(t => t.LoginProvider).ToList();
                return(model);
            }
            return(null);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Register(UserViewModel userVM)
        {
            ViewBag.State = "Register"; //used to track if user is logging in or registering on integrated page
            if (ModelState.IsValid)
            {
                var newUser = new LaughUser {
                    UserName = userVM.Username
                };
                var registerSuccess = await _userManager.CreateAsync(newUser, userVM.Password);

                if (!registerSuccess.Succeeded)
                {
                    _logger.LogError(registerSuccess.Errors.ToString());
                    ModelState.AddModelError("Password", "Password must be at least 8 characters long and contain a combination of letters and numbers.");
                }
                else
                {
                    await _signInManager.SignInAsync(newUser, isPersistent : false);

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

            var userStats = new UserStatsViewModel();

            return(View("Index", userStats));
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> Login(LoginBindingModel login)
        {
            var user = await UserManager.FindAsync(login.UserName, login.Password).ConfigureAwait(false);

            if (user != null)
            {
                var identity = await UserManager.CreateIdentityAsync(user, CookieAuthenticationDefaults.AuthenticationType).ConfigureAwait(false);

                Authentication.SignIn(new AuthenticationProperties()
                {
                    IsPersistent = login.RememberMe
                }, identity);

                UserStatsViewModel model = new UserStatsViewModel(user, true);
                if (string.IsNullOrEmpty(user.AvatarFull) && !Guid.TryParse(user.Id, out Guid newguid))
                {
                    model = await SteamServiceProvider.GetSteamUserDetails(user.Id).ConfigureAwait(false);

                    model.SetUser(user);
                }
                model.externalLogins = UserManager.GetLogins(user.Id).Select(t => t.LoginProvider).ToList();
                return(Ok(model));
            }
            return(BadRequest("Invalid username or password."));
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> GetUserDetails(string userid)
        {
            UserStatsViewModel user = await SteamServiceProvider.GetSteamUserDetails(userid).ConfigureAwait(false);

            ApplicationUser registered = null;

            if (user.steamUser != null)
            {
                registered = _dbContext.Users.Include(u => u.MemberOf).FirstOrDefault(u => u.Id == user.steamUser.steamID64);
            }
            if (registered != null)
            {
                user.SetUser(registered);
            }
            return(Ok(user));
        }
        public async Task <IActionResult> Get(string userid)
        {
            UserStatsViewModel user = await _steamService.GetSteamUserDetails(userid);

            ApplicationUser registered = null;

            if (user.SteamUser != null)
            {
                registered = await _dbContext.Users.Include(u => u.MemberOf).ThenInclude(m => m.Team).FirstOrDefaultAsync(u => u.SteamID == user.SteamUser.steamID64);
            }
            if (registered != null)
            {
                user.SetUser(registered, _dbContext);
            }
            return(Ok(user));
        }
Ejemplo n.º 6
0
        public IActionResult Index(string ReturnUrl) //main page + login / register form
        {
            if (!string.IsNullOrEmpty(ReturnUrl) && ReturnUrl.Length > 0)
            {
                ViewBag.Auth = "needed";
            }
            var userId    = _userManager.GetUserId(HttpContext.User);
            var thisUser  = _repo.GetUser(userId);
            var userStats = new UserStatsViewModel();

            if (thisUser != null)
            {
                userStats.UserName = thisUser.UserName;
                userStats.Jokes    = thisUser.Jokes;
                userStats.Ratings  = thisUser.Ratings;
            }
            else
            {
                userStats.UserName = "";
            }

            return(View(userStats));
        }
Ejemplo n.º 7
0
        public static UserStatsViewModel ReadUserStats(int userId, bool fullStats)
        {
            var userStats = new UserStatsViewModel();
            var user      = DependencyResolver.Current.GetService <IUserService>().GetEntityById(userId);

            if (user != null)
            {
                userStats.DaysInService = (DateTime.Now - user.RegisterDate).Days;
                userStats.TotalComments = DependencyResolver.Current.GetService <ICommentService>().GetUserCommentsCountByUserId(userId);
                if (fullStats)
                {
                    userStats.TotalPublications =
                        DependencyResolver.Current.GetService <ITextDescriptionService>()
                        .GetUserPublicationsCount(userId);
                    if (userStats.TotalPublications != 0)
                    {
                        userStats.AverageRating =
                            DependencyResolver.Current.GetService <IRatingService>().GetAverageRatingForUser(userId);
                    }
                }
            }
            return(userStats);
        }
Ejemplo n.º 8
0
        public ActionResult UsageStats()
        {
            UserStatsViewModel vm = new UserStatsViewModel();

            vm.UserAlias        = "Eugenio";
            vm.IndividualPeriod = new List <SelectListItem>()
            {
                new SelectListItem {
                    Text = "Today", Value = "Today", Selected = false
                },
                new SelectListItem {
                    Text = "Week", Value = "Week", Selected = true
                },
                new SelectListItem {
                    Text = "Total", Value = "Total", Selected = false
                }
            };
            vm.Participants = new List <Participant>()
            {
                new Participant {
                    Alias = "Alias1", Rank = 20, Hours = 345
                },
                new Participant {
                    Alias = "Alias5", Rank = 19, Hours = 265
                },
                new Participant {
                    Alias = "Alias1", Rank = 18, Hours = 165
                },
                new Participant {
                    Alias = "Alias2", Rank = 10, Hours = 99
                },
                new Participant {
                    Alias = "Alias6", Rank = 5, Hours = 4
                },
            };
            return(View(vm));
        }
Ejemplo n.º 9
0
        public async Task <IHttpActionResult> GetUserGroups(string userid)
        {
            UserStatsViewModel user = await SteamServiceProvider.GetSteamUserDetails(userid).ConfigureAwait(false);

            return(Ok(user?.steamUser?.groups));
        }
        public async Task <IActionResult> GetUserGroups(string userid)
        {
            UserStatsViewModel user = await _steamService.GetSteamUserDetails(userid);

            return(Ok(user?.SteamUser?.groups));
        }