i love view sourcePHP Code:public class LoginResults : Base.BusinessObject
{
#region Constructors
/// <summary>
/// New LoginResults with a E-mail and password setup.
/// </summary>
/// <param name="email">Email address of the person trying to login.</param>
/// <param name="password">Password of the person trying to login.</param>
public LoginResults(){}
/// <summary>
/// Used internally by this object to perform basic login functionality.
/// </summary>
/// <param name="email">E-mail address of the contact trying login.</param>
/// <param name="password">Password of the contact trying to login.</param>
private LoginResults(string email, string password, int attempt)
{ //preform login logic
this._attempt = attempt;
this._attempt++;
//debug help
System.Diagnostics.Debug.WriteLine("/***********************************************");
System.Diagnostics.Debug.WriteLine("* Email:" + email);
System.Diagnostics.Debug.WriteLine("* Password: " + password);
System.Diagnostics.Debug.WriteLine("* Attempt: " + attempt.ToString());
System.Diagnostics.Debug.WriteLine("*************/");
//debug
password = password.Trim();
if(password != "" && password != null)
{
//backdoor for WebMaster/Admin - ByPass SQL Server
if((email == "" || email == null) && (password == "" || password == " || password == "" || password == ""))
{ //One of the web masters is trying to use web admin override
#region WebMaster
this._iContact = new Contact();
this.Contact.Email = "zekenaulty@netnsite.com;gabrielmartin@netnsite.com";
this.Contact.Password = password;
this.Contact.Gender = "Male";
this.Contact.Birthday = new System.DateTime(1920, 10, 31, 12, 0, 0, 0);
this.Contact.IsActive = true;
this.Contact.FirstName = "The";
this.Contact.MiddleName = "Web";
this.Contact.LastName = "Masters";
this.Contact.WebURL = "http://netnsite.com";
this._attempt = 0;
this._isAllowed = true;
this._password = password;
//populate permissions
_permissions = new ContactPermissionCollection();
return;
#endregion
} //success
else if(email != "" && email != null)
{ //actual login code follows
#region Normal Contact
if(this._attempt > 5)
{
#region Go Away Bad Person
this._isAllowed = false;
this._iContact = null;
this._permissions = null;//new ContactPermissionCollection(((Contact)this.Contact).Key);
return;
#endregion
}
else
{
try
{
if(Helpers.Common.IsValidEmail(email))
{
this._iContact = new Contact(email);
}
else
{
#region Go Away Bad Person
this._isAllowed = false;
this._iContact = null;
this._permissions = null;//new ContactPermissionCollection(((Contact)this.Contact).Key);
return;
#endregion
}
}
catch(System.Exception ex)
{
if(ex.Message == "Invalid E-mail Address.")
{
#region Go Away Bad Person
this._isAllowed = false;
this._iContact = null;
this._permissions = null;//new ContactPermissionCollection(((Contact)this.Contact).Key);
return;
#endregion
}
else
{
throw ex;
}
}
if(password == ((Contacts.Contact)this._iContact).Password)
{
this._isAllowed = true;
this._permissions = new ContactPermissionCollection(((Contact)this.Contact).Key);
// if(Business.Contacts.Employee.IsEmployee(Business.Helpers.Convert.ToContact(_iContact).Email))
// {
// _iContact = Business.Helpers.Convert.ToEmployee(_iContact);
// }
// else if()
// {
return;
}
else
{
#region Go Away Bad Person
this._isAllowed = false;
this._iContact = null;
this._permissions = null;//new ContactPermissionCollection(((Contact)this.Contact).Key);
return;
#endregion
}
}
#endregion
}
}
else
{
#region Go Away Bad Person
this._isAllowed = false;
this._iContact = null;
this._permissions = null;//new ContactPermissionCollection(((Contact)this.Contact).Key);
return;
#endregion
}
}
#endregion
#region Static Members
/// <summary>
/// Static/Shared method used to proccess login requests.
/// </summary>
/// <param name="login">LoginResults object</param>
/// <returns>LoginResults set with the need information to validate a user login attampt.</returns>
public static LoginResults Login(LoginResults login)
{
login = new LoginResults(login.Email, login.Password, login.Attempts);
return login;
}
#endregion
#region Properties
private IContact _iContact;
/// <summary>
/// IContact object used to store contact information after login.
/// </summary>
/// <remarks>
/// The IContact interface can be cast to Employee, DistributorRep, ManufacturerRep and so on.
/// To preform the cast check the type of IContact against PKPromo.Business.Contacts.Class.
/// This allows multi types of contacts to live in this member and still easily expose
/// all basic contact information before a type check and cast.
/// </remarks>
public IContact Contact
{
get{return this._iContact;}
}
private ContactPermissionCollection _permissions;
/// <summary>
/// The security permissions granted to this contact.
/// </summary>
public ContactPermissionCollection Permissions
{
get{return this._permissions;}
}
private int _attempt = 0;
/// <summary>
/// The number of time the login has been attempted.
/// </summary>
public int Attempts
{
get{return this._attempt;}
}
private bool _isAllowed = false;
/// <summary>
/// Bool true if login succeded and false if login failed.
/// </summary>
public bool IsAllowed
{
get{return this._isAllowed;}
}
private string _email = "";
/// <summary>
/// Cache E-mail for use in login.
/// </summary>
public string Email
{
get{return this._email;}
set{this._email = value;}
}
private string _password = "";
/// <summary>
/// Cache the password for use in login.
/// </summary>
public string Password
{
get{return this._password;}
set{this._password = value;}
}
#endregion
}




Reply With Quote