Advertisement
lightningstalon

Neofriends Authorization (C#)

Feb 4th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using Authorization;
  7.  
  8. public partial class frmMain : Form
  9. {
  10.     public frmMain()
  11.     {
  12.         InitializeComponent();
  13.     }
  14.  
  15.     #region "Authorization"
  16.    
  17.     private void btnAuthorize_Click(object sender, EventArgs e)
  18.     {
  19.         //Validate that user has entered correct information in textboxes.
  20.        
  21.         //Use NFAuth's constructor to your full advantage
  22.         NFAuth auth = new NFAuth(txtUsername.Text, txtPassword.Text, PROGRAM_ID, PROGRAM_NAME, this, UpdateSub: Auth_UpdateHandler, AuthorizedSub: Auth_AuthorizedHandler, UnAuthorizedSub: Auth_UnauthorizedHandler, ExceptionSub: Auth_ExceptionHandler);
  23.  
  24.         //Settings can also be set like this:
  25.         auth.StatusLabel = lblStatus;
  26.  
  27.         //Authorize asynchronously so it doesn't freeze the GUI
  28.         auth.AuthorizeASync();
  29.  
  30.         //Disable your authorize button
  31.         btnAuthorize.Enabled = false;
  32.     }
  33.  
  34.     private void Auth_ExceptionHandler(Exception ex)
  35.     {
  36.         //Handle the exception (stuff like Debug.Print() might help with debugging)
  37.     }
  38.  
  39.     private void Auth_AuthorizedHandler()
  40.     {
  41.         //Do something when they are authorized
  42.     }
  43.  
  44.     private void Auth_UnauthorizedHandler()
  45.     {
  46.         btnAuthorize.Enabled = true;
  47.         //Do something for handling unauthorized.
  48.     }
  49.  
  50.     private void Auth_UpdateHandler()
  51.     {
  52.         //You can either require the user to update before using or just use the outdated version.
  53.     }
  54.  
  55.     #endregion
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement