Ejemplo n.º 1
0
        public static UserEntity UpdateTicket(string device, ref string ticket)
        {
            using (AuthLogic.Disable())
                using (var tr = new Transaction())
                {
                    var pair = UserTicketEntity.ParseTicket(ticket);

                    UserEntity user = Database.Retrieve <UserEntity>(pair.userId);
                    CleanExpiredTickets(user);

                    UserTicketEntity?userTicket = user.UserTickets().SingleOrDefaultEx(t => t.Ticket == pair.ticket);
                    if (userTicket == null)
                    {
                        throw new UnauthorizedAccessException("User attempted to log-in with an invalid ticket");
                    }

                    UserTicketEntity result = new UserTicketEntity
                    {
                        User           = user.ToLite(),
                        Device         = device,
                        ConnectionDate = TimeZoneManager.Now,
                        Ticket         = Guid.NewGuid().ToString(),
                    }.Save();

                    ticket = result.StringTicket();

                    return(tr.Commit(user));
                }
        }
Ejemplo n.º 2
0
        public static string NewTicket(string device)
        {
            using (AuthLogic.Disable())
                using (var tr = new Transaction())
                {
                    CleanExpiredTickets(UserEntity.Current);

                    UserTicketEntity result = new UserTicketEntity
                    {
                        User           = UserEntity.Current.ToLite(),
                        Device         = device,
                        ConnectionDate = TimeZoneManager.Now,
                        Ticket         = Guid.NewGuid().ToString(),
                    };

                    result.Save();

                    return(tr.Commit(result.StringTicket()));
                }
        }