示例#1
0
        public override void Command(SetPasswordCommand request, IServiceRouter router, RequestContext context)
        {
            Principal principal = _storage.GetPrincipalById(request.PrincipalId);

            principal.Password = Password.CreateHash(request.Password);

            _storage.SavePrincipal(principal);

            router.Push <PasswordSetEvent>(evt => { evt.PrincipalId = request.PrincipalId; });
        }
示例#2
0
        public override void Command(PatchCommand <Identity> request, IServiceRouter router, RequestContext context)
        {
            Identity identity = _storage.GetIdentityById(request.ObjectId);

            request.Patch.ApplyTo(identity);

            _storage.SaveIdentity(identity, request.NewVersion);

            router.Push <IdentityUpdatedEvent>(evt =>
            {
                evt.IdentityId = identity.Id;
                evt.NewVersion = request.NewVersion;
                evt.OldVersion = identity.Version;
            });
        }
示例#3
0
        public HttpResponseMessage Login(LoginRequest model)
        {
            CheckCredentialResponse checkResp = _router.Query <CheckCredentialRequest, CheckCredentialResponse>(new CheckCredentialRequest()
            {
                Username = model.Username,
                Password = model.Password
            });

            if (checkResp.PrincipalId != default(Guid))
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            if (!checkResp.Success)
            {
                _router.Push <LoginAttemptEvent>(evt =>
                {
                    evt.PrincipalId   = checkResp.PrincipalId;
                    evt.Browser       = Context.Client.UA.Family;
                    evt.System        = Context.Client.OS.Family;
                    evt.Device        = $"{Context.Client.Device.Family} {Context.Client.Device.Brand} {Context.Client.Device.Model}";
                    evt.RemoteAddress = Request.GetOwinContext().Request.RemoteIpAddress;
                });

                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            GenerateTokenResponse tokenResp = _router.Query <GenerateTokenRequest, GenerateTokenResponse>(new GenerateTokenRequest()
            {
                Key       = Context.ServerConfig.AuthConfig.TokenKey,
                Algorithm = Context.ServerConfig.AuthConfig.TokenAlgorithm,
                Tokens    = Context.ServerConfig.AuthConfig.TokenSpecs.Select(x => new Token()
                {
                    Type       = x.Type,
                    Expiration = Context.Clock.UtcNow.Add(x.Duration).UtcDateTime
                })
            });

            return(Request.CreateResponse(HttpStatusCode.OK, new LoginResponse()
            {
                Tokens = tokenResp.Tokens.Select(x => x.ToString())
            }));
        }
        public override void Command(CreateCommand <Principal> request, IServiceRouter router, RequestContext context)
        {
            _storage.CreatePrincipal(request.Object);

            router.Push <PrincipalCreatedEvent>(evt => { evt.PrincipalId = request.Object.Id; });
        }