Esempio n. 1
0
 public DocumentController(DocumentService service,
                           PermissionService permission,
                           CurrentAuth auth)
 {
     _service    = service;
     _permission = permission;
     _user       = auth.TryGet <UserAuth>();
 }
Esempio n. 2
0
        public void Authenticate(CurrentAuth auth, UserCredentialsDto credentials)
        {
            var user = Repository.FindByEmail(credentials.Email.ToLower());

            if (user == null || user.Password != credentials.Password)
            {
                throw new ValidationFieldException(nameof(credentials.Password), "Nome ou senha incorretos!");
            }

            if (!user.Active)
            {
                throw new ValidationFieldException(nameof(credentials.Email), "Sua conta está desativada!");
            }

            _userAuthProvider.Load(user, auth);
        }
Esempio n. 3
0
        public CurrentAuth Get(Guid guid)
        {
            CurrentAuth auth;

            lock (_auths) {
                _auths.TryGetValue(guid, out auth);

                if (auth == null)
                {
                    _auths[guid] = auth = new CurrentAuth(guid);
                }
            }

            auth.LastAction = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            return(auth);
        }
Esempio n. 4
0
        public async Task Invoke(HttpContext context, CurrentAuth holder)
        {
            context.Items[AuthorizationMiddlewareInvokedWithEndpointKey] = AuthorizationMiddlewareWithEndpointInvokedValue;

            var endpoint = context.GetEndpoint();

            if (endpoint == null)
            {
                await _next(context);

                return;
            }

            var authorizeData = endpoint.Metadata.GetOrderedMetadata <IAuthorizeData>() ?? Array.Empty <IAuthorizeData>();

            if (endpoint.Metadata.GetMetadata <IAllowAnonymous>() != null)
            {
                await _next(context);

                return;
            }

            if (authorizeData.Any())
            {
                if (!holder.Authenticated)
                {
                    context.Response.Redirect("/Auth/Login");
                    return;
                }

                var auth = holder.TryGet <IAuth>();

                if (authorizeData.Any(data => data.Roles != null && !auth.HasRole(data.Roles)))
                {
                    await context.Response.WriteAsync("fail");

                    return;
                }
            }

            await _next(context);
        }
Esempio n. 5
0
 public void Load(User user, CurrentAuth auth)
 {
     auth.Set(ToAuth(user), this);
 }
Esempio n. 6
0
 public AuthController(UserService service, CurrentAuth auth)
 {
     _service = service;
     _auth    = auth;
 }