示例#1
0
        public static bool IsValidAdminToken(string token)
        {
            using (var context = new BoxingContext())
            {
                var login = context.Logins.Where(l => l.AuthToken == token).FirstOrDefault();

                if (login != null && login.ExpirationDate.IsValidExpirationDate())
                {
                    var user = context.Users.FirstOrDefault(u => u.Id == login.UserId);
                    if (user != null && user.IsAdmin)
                    {
                        login.ExpirationDate = DateTimeExtensions.CreateExpirationDate();
                        context.SaveChangesAsync();
                        return true;
                    }
                }
            }

            return false;
        }
示例#2
0
        public static bool IsValidToken(string token)
        {
            if (token == "logintoken" || token == "registertoken")
            {
                return true;
            }

            using (var context = new BoxingContext())
            {
                var login = context.Logins.Where(l => l.AuthToken == token).FirstOrDefault();

                if (login != null && login.ExpirationDate.IsValidExpirationDate())
                {
                    login.ExpirationDate = DateTimeExtensions.CreateExpirationDate();
                    context.SaveChangesAsync();
                    return true;
                }
            }

            return false;
        }
示例#3
0
 public AdminAttribute()
 {
     _db = new BoxingContext();
 }
示例#4
0
 public AuthAttribute()
 {
     _db = new BoxingContext();
 }