ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!
Home
Upgrade
Credits
Help
Search
Awards
Achievements
 2398

LLS - C# Console Auth System

by Venipa - 02-03-2018 - 12:27 PM
#1
Code:
using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using LLS;

namespace LLS.Test
{
   class Program
   {
       Client _client;
       UserModel UserInfo;
       static void Main(string[] args)
       {
           new Program().Start().Wait();
       }
       async Task Start()
       {
           await AuthBasic();
           await Task.Delay(-1);
       }
       async Task AuthBasic()
       {
           _client = new Client();
           var AuthResponse = await _client.Authenticate("Your App Key");
           if(AuthResponse.IsError)
           {
               Console.WriteLine(AuthResponse.Error);
               Console.ReadKey();
               Environment.Exit(0);
           }
           var LoginResponse = await _client.Login("email", "password");
           if(LoginResponse.IsError)
           {
               Console.WriteLine(LoginResponse.Error);
               Console.ReadKey();
               Environment.Exit(0);
           }
           UserInfo = LoginResponse.Model.User;
           if(UserInfo.HasActiveLicense)
           {
               await ActualProgram();
           } else
           {
               Console.Write("No Active License Detected, want to redeem a working one? (Y/N):");
               if(Console.ReadKey().Key == ConsoleKey.Y)
               {
                   Console.Write("Type in your new License: ");
                   string key = Console.ReadLine();
                   var RedeemResponse = await _client.Redeem(key);
                   if(RedeemResponse.IsError)
                   {
                       Console.WriteLine(LoginResponse.Error);
                       Console.ReadKey();
                       Environment.Exit(0);
                   }
                   if(RedeemResponse.Model.IsLifetime || RedeemResponse.Model.EndingAt > DateTime.Now)
                   {
                       await ActualProgram();
                   } else
                   {
                       Console.WriteLine("Expired License");
                       Console.ReadKey();
                       Environment.Exit(0);
                   }
               } else
               {
                   Console.WriteLine("Exiting in 5 Seconds...");
                   await Task.Delay(5*1000);
                   Environment.Exit(0);
               }
           }
       }
       async Task ActualProgram()
       {
           Console.WriteLine("Welcome " + UserInfo.Username + " to " + Assembly.GetExecutingAssembly().FullName);
       }
   }
}

Uses Auth System from LLS 
Reply
#2
Damn, this is nice, thanks for sharing! :D
Reply

Users browsing: 1 Guest(s)