예제 #1
0
        public async Task <Build> CreateBuild()
        {
            var uid = _ua.AuthenticateUser(this);

            if (uid == null)
            {
                HttpContext.Response.StatusCode = 401;
                return(null);
            }

            var b = new Build
            {
                Id          = System.Guid.NewGuid().ToString("N"),
                Creator     = uid.UserId,
                Created     = DateTime.UtcNow,
                Modified    = DateTime.UtcNow,
                Parts       = new List <Part>(),
                Images      = new List <Image>(),
                Title       = string.Empty,
                Description = string.Empty
            };

            var bstr = JsonConvert.SerializeObject(b);

            await this._data.AddKeyAsync(BuildNamespace + b.Id, bstr);

            await ListHelper.AddToList(_data, UserController.UserBuildNamespace, uid.UserId, b.Id);

            await ListHelper.EnqueueList(_data, BuildController.RecentBuildNamespace, BuildController.RecentBuildName, b.Id);

            await this._search.AddBuildsToIndexAsync(new Build[] { b });

            return(b);
        }
예제 #2
0
        public async Task <BuildList> CreateList()
        {
            var uid = _ua.AuthenticateUser(this);

            if (uid == null)
            {
                HttpContext.Response.StatusCode = 401;
                return(null);
            }

            var bl = new BuildList()
            {
                Id          = Guid.NewGuid().ToString("N"),
                Creator     = uid.UserId,
                Title       = string.Empty,
                Description = string.Empty,
                Builds      = new List <string>(),
                Created     = DateTime.UtcNow,
                Modified    = DateTime.UtcNow
            };

            await this._data.AddKeyAsync(ListNamespace + bl.Id, JsonConvert.SerializeObject(bl));

            await ListHelper.AddToList(_data, UserController.UserListNamespace, uid.UserId, bl.Id);

            return(bl);
        }
        public async Task CheckUser(ValidateCredentialsContext context, CancellationToken cancellationToken)
        {
            var userName = context.Username;

            logger.LogInformation("Authenticating the user {UserName} ...", userName);

            var userId = await userAuthenticator.AuthenticateUser(userName, context.Password, cancellationToken);

            if (userId != null)
            {
                logger.LogInformation("The user {UserName} was authenticated successfully", userName);

                var claims = new[]
                {
                    new Claim(ClaimTypes.NameIdentifier, userId),
                    new Claim(ClaimTypes.Name, userName),
                };

                context.Principal = new ClaimsPrincipal(new ClaimsIdentity(claims, context.Scheme.Name));
                context.Success();
                return;
            }

            logger.LogWarning("Failed to authenticate user {UserName}", userName);
            context.Fail("The user name or password is incorrect");
        }
예제 #4
0
        public IActionResult Index()
        {
            ViewBag.SiteSettings = ss;
            var loginInfo = _ua.AuthenticateUser(this);

            if (loginInfo == null)
            {
                ViewBag.UserIsAuthenticated = false;
                ViewBag.UserIdentityName    = "";
                ViewBag.UserIdentityKey     = "";
            }
            else
            {
                // lets give them a cookie
                if (string.IsNullOrEmpty(loginInfo.Hmac))
                {
                    var cookieValue = _ua.GenerateCookie(loginInfo);
                    HttpContext.Response.Cookies.Append(UserAuthenticator.CookieName, cookieValue);
                }

                ViewBag.UserIsAuthenticated = true;
                ViewBag.UserIdentityName    = loginInfo.FriendlyName;
                ViewBag.UserIdentityKey     = loginInfo.UserId;
            }

            return(View());
        }