public IMaybe <Jwt.TokenBundle> MaybeLogin(PotentialUser potentialUser)
        {
            var maybeUser = _userRepository.MaybeGetOne(potentialUser.Username);

            return(maybeUser.Case(
                       some: user =>
            {
                var isUsersAccountDisabled = !user.IsActive;
                if (isUsersAccountDisabled)
                {
                    return None <Jwt.TokenBundle> .Exists;
                }

                var isPasswordCorrect = PasswordService.Validate(potentialUser.Password, user.Password);
                if (!isPasswordCorrect)
                {
                    return None <Jwt.TokenBundle> .Exists;
                }

                var sesssion = _sessionCommand.Execute(new SessionCommand.Create(
                                                           user: user,
                                                           startedOn: DateTime.Now
                                                           ));

                return Some <Jwt.TokenBundle> .Exists(new Jwt.TokenBundle(
                                                          bearerToken: new Jwt.BearerToken(username: user.Username, role: user.Role),
                                                          refreshToken: new Jwt.RefreshToken(id: sesssion.Id, startedOn: sesssion.StartedOn)
                                                          ));
            },
                       none: () => None <Jwt.TokenBundle> .Exists));
        }
Esempio n. 2
0
        public IMaybe <User.ShortDetails> MaybeGetOne(Guid id)
        {
            var maybeUser = _attendeeRegistrationContext.Users.Find(id);

            return(maybeUser == null
                ? None <User.ShortDetails> .Exists
                : Some <User.ShortDetails> .Exists(UserMapper.MapShortDetails(maybeUser)));
        }
Esempio n. 3
0
        public IMaybe <User.LongDetails> MaybeGetOne(string username)
        {
            var maybeUser = _attendeeRegistrationContext.Users.SingleOrDefault(user => user.Username == username);

            return(maybeUser == null
                ? None <User.LongDetails> .Exists
                : Some <User.LongDetails> .Exists(UserMapper.MapLongDetails(maybeUser)));
        }
Esempio n. 4
0
        public IMaybe <Session> MaybeGetOne(Guid id)
        {
            var maybeSession = _attendeeRegistrationContext.Sessions.Find(id);

            return(maybeSession == null
                ? None <Session> .Exists
                : Some <Session> .Exists(SessionMapper.Map(maybeSession)));
        }
Esempio n. 5
0
        public IMaybe <Attendee.ShortDetails> GetOne(Guid id)
        {
            var attendee = _attendeeRegistrationContext.Attendees.Find(id);

            if (attendee == null)
            {
                return(None <Attendee.ShortDetails> .Exists);
            }

            return(Some <Attendee.ShortDetails> .Exists(AttendeeMapper.MapShortDetails(attendee)));
        }
        public IMaybe <Attendee.ShortDetails> Execute(Print command)
        {
            var attendee = _attendeeRegistrationContext.Attendees.Find(command.Id);

            if (attendee == null)
            {
                return(None <Attendee.ShortDetails> .Exists);
            }

            attendee.IsAccreditationPrinted = true;

            _attendeeRegistrationContext.SaveChanges();
            return(Some <Attendee.ShortDetails> .Exists(AttendeeMapper.MapShortDetails(attendee)));
        }
        public IMaybe <Jwt.BearerToken> MaybeCreateBearerToken(Jwt.RefreshToken refreshToken)
        {
            if (refreshToken.HasExpired)
            {
                return(None <Jwt.BearerToken> .Exists);
            }

            var maybeSession = _sessionRepository.MaybeGetOne(refreshToken.Id);

            return(maybeSession.Case(
                       some: session => Some <Jwt.BearerToken> .Exists(new Jwt.BearerToken(
                                                                           username: session.User.Username, role: session.User.Role
                                                                           )),
                       none: () => None <Jwt.BearerToken> .Exists
                       ));
        }
Esempio n. 8
0
 public static IMaybe <BearerToken> CreateIfValid(string token)
 {
     return(IsValid(token)
         ? Some <BearerToken> .Exists(new BearerToken(token))
         : None <BearerToken> .Exists);
 }