Example #1
0
	public async void OnClickButtonRegister(object sender, EventArgs e)
	{
		DateTime defaultDt = DateTime.Parse("01/01/1900");
		PresentationAccessObject p = new PresentationAccessObject();
		User u = new User();
		LoginCredentials l = new LoginCredentials();
		string loginCred = txtLoginCred.Text, passwd = txtPasswd.Text;
		l.Password = passwd;
		bool isValidEmail = await p.IsValidEmailAsync(loginCred), isValidContact = await p.IsValidContactAsync(loginCred);
		if (isValidContact)
		{
			u.Contact = loginCred;
			u.EmailAddress = "not_set";
		}
		if (isValidEmail)
		{
			u.EmailAddress = loginCred;
			u.Contact = "not_set";
		}
		u.FirstName = u.LastName = u.City = "not_set";
		u.DateOfBirth = defaultDt;
		if(chk.Checked)
		{
			bool registerSuccess = await p.RegisterAsync(u, l);
			if (registerSuccess)
				Response.Redirect("profile.aspx");
		}
	}
		async void BindNameToLabel()
		{
			LoginCredentials c = new LoginCredentials();
			PresentationAccessObject p = new PresentationAccessObject();
			bool isEmail = await p.IsValidEmailAsync(loginCred), isContact = await p.IsValidContactAsync(loginCred);
			if(isEmail)
			{
				c.EmailAddress = loginCred;
				c.Contact = string.Empty;
			}
			if(isContact)
			{
				c.Contact = loginCred;
				c.EmailAddress = string.Empty;
			}
			displayName = await p.NameGiveLoginCredentialAsync(c);
			DispName.Text = displayName;
		}
Example #3
0
	public async void OnButtonLogin(object sender, EventArgs e)
	{
		PresentationAccessObject p = new PresentationAccessObject();
		LoginCredentials l = new LoginCredentials();
		try
		{
			l.Password = txtPassword.Text;
			string loginCred = txtLoginCred.Text;
			bool isValidEmail = await p.IsValidEmailAsync(loginCred), isValidContact = await p.IsValidContactAsync(loginCred);
			if (!isValidContact && !isValidEmail)
				throw new Exception();
			else
			{
				if (isValidEmail)
				{
					l.EmailAddress = loginCred;
					l.Contact = string.Empty;
				}
				if (isValidContact)
				{
					l.Contact = loginCred;
					l.EmailAddress = string.Empty;
				}
			}
			bool login = await p.LoginAsync(l);
			if (login)
			{
				Session["loginCred"] = loginCred;	//buggy
				Response.Redirect("profile.aspx");				
			}
			else
				throw new Exception();
		}
		catch (Exception ex)
		{
			DirectoryInfo d = Directory.CreateDirectory("E:\\Visual Studio Projects\\NKryptor\\ErrorLogs\\WebApp");
			FileStream errorLog = File.OpenWrite("E:\\Visual Studio Projects\\NKryptor\\ErrorLogs\\WebApp\\Error.log");
			byte[] errorInfo = Encoding.Default.GetBytes(ex.Message + "\n" + ex.StackTrace), time = Encoding.Default.GetBytes("At time (IST) " + DateTime.Now.ToString()), newLn = Encoding.Default.GetBytes(Environment.NewLine);
			errorLog.Write(time, 0, time.Length);
			errorLog.Write(newLn, 0, newLn.Length);
			errorLog.Write(errorInfo, 0, errorInfo.Length);
			errorLog.Close();
		}
	}
 public bool CheckAccountExists(LoginCredentials l)
 {
     bool exists = false;
     bool? checkResult = false;
     try
     {
         if (l.EmailAddress.Equals(string.Empty))
             checkResult = linqDc.FuncCheckAccount(null, l.Contact);
         if (l.Contact.Equals(string.Empty))
             checkResult = linqDc.FuncCheckAccount(l.EmailAddress, null);
         if (checkResult == true)
             exists = true;
     }
     catch (Exception e)
     {
         errorLogDal = File.OpenWrite("E:\\Visual Studio Projects\\NKryptor\\ErrorLogs\\AccessLayers\\ErrorDal.log");
         errorInfo = Encoding.UTF32.GetBytes(e.Message + "\n" + e.StackTrace);
         errorLogDal.Write(errorInfo, 0, errorInfo.Length);
         errorLogDal.Close();
     }
     return exists;
 }
Example #5
0
	async void BindFirstName()
	{
		LoginCredentials l = new LoginCredentials();
		string name = string.Empty;
		PresentationAccessObject p = new PresentationAccessObject();		
		try
		{
			string loginCred = ( string )Session["login"];
			bool validContact = await p.IsValidContactAsync(loginCred),
				 validEmail = await p.IsValidEmailAsync(loginCred);
			if(validEmail)
			{
				l.EmailAddress = loginCred;
				l.Contact = string.Empty;
			}
			if(validContact)
			{
				l.Contact = loginCred;
				l.EmailAddress = string.Empty;
			}
			name = await p.NameGiveLoginCredentialAsync(l);
			if (name.Equals(string.Empty))
			{
				lblName.Text = loginCred;
			}
			else lblName.Text = name;
		}
		catch (Exception ex)
		{
			DirectoryInfo d = Directory.CreateDirectory("E:\\Visual Studio Projects\\NKryptor\\ErrorLogs\\WebApp");
			FileStream errorLog = File.OpenWrite("E:\\Visual Studio Projects\\NKryptor\\ErrorLogs\\WebApp\\Error.log");
			byte[] errorInfo = Encoding.Default.GetBytes(ex.Message + "\n" + ex.StackTrace), time = Encoding.Default.GetBytes("At time (IST) " + DateTime.Now.ToString()), newLn = Encoding.Default.GetBytes(Environment.NewLine);
			errorLog.Write(time, 0, time.Length);
			errorLog.Write(newLn, 0, newLn.Length);
			errorLog.Write(errorInfo, 0, errorInfo.Length);
			errorLog.Close();
		}
	}
 public Task<bool> UpdatePasswordAsync(LoginCredentials l, string oldPassword, string newPassword)
 {
     return Task.Run<bool>(() => UpdatePassword(l, oldPassword, newPassword));
 }
 public bool UpdatePassword(LoginCredentials l, string oldPassword, string newPassword)
 {
     bool updateSuccess = false;
     int updateResult;
     try
     {
         if(l.Contact.Equals(string.Empty))
         {
             updateResult = linqDc.ProcUpdatePassword(l.EmailAddress, string.Empty, oldPassword, newPassword);
             if (updateResult == 0)
                 updateSuccess = true;
         }
         else
         if(l.EmailAddress.Equals(string.Empty))
         {
             updateResult = linqDc.ProcUpdatePassword(string.Empty, l.Contact, oldPassword, newPassword);
             if (updateResult == 0)
                 updateSuccess = true;
         }
     }
     catch (Exception e)
     {
         errorInfo = Encoding.UTF32.GetBytes(e.Message + "\n" + e.StackTrace);
         errorLogDal = File.OpenWrite("E:\\Visual Studio Projects\\NKryptor\\ErrorLogs\\AccessLayers\\ErrorDal.log");
         errorLogDal.Write(errorInfo, 0, errorInfo.Length);
         errorLogDal.Close();
     }
     return updateSuccess;
 }
 public Task<bool> ResetPasswordAsync(LoginCredentials l, string newPassword)
 {
     return Task.Run<bool>(() => ResetPassword(l, newPassword));
 }
 public bool ResetPassword(LoginCredentials l, string newPassword)
 {
     bool resetSuccess = false;
     int resetResult = 0, clearResult = 0;
     try
     {
         if(l.Contact.Equals(string.Empty))
         {
             clearResult = linqDc.ProcClearPassword(l.EmailAddress, null);
             if (clearResult == 0)
                 resetResult = linqDc.ProcResetPassword(l.EmailAddress, null, newPassword);
         }
         if(l.EmailAddress.Equals(string.Empty))
         {
             clearResult = linqDc.ProcClearPassword(null, l.Contact);
             if (clearResult == 0)
                 resetResult = linqDc.ProcResetPassword(null, l.Contact, newPassword);
         }
         if (resetResult == 0)
             resetSuccess = true;
     }
     catch (Exception e)
     {
         DirectoryInfo d = Directory.CreateDirectory("E:\\Visual Studio Projects\\NKryptor\\ErrorLogs\\AccessLayers");
         errorInfo = Encoding.Default.GetBytes(e.Message + "\n" + e.StackTrace);
         errorLogDal = File.OpenWrite("E:\\Visual Studio Projects\\NKryptor\\ErrorLogs\\AccessLayers\\ErrorDal.log");
         errorLogDal.Seek(0, SeekOrigin.Begin);
         errorLogDal.Write(errorInfo, 0, errorInfo.Length);
         errorLogDal.Close();
     }
     return resetSuccess;
 }
 public Task<bool> RegisterAsync(User u, LoginCredentials l)
 {
     return Task.Run<bool>(() => Register(u, l));
 }
 public bool Register(User u, LoginCredentials l)
 {
     bool registerSuccess = false;
     try
     {
         int registerResult = linqDc.ProcRegister(u.FirstName, u.LastName, u.EmailAddress, u.Contact, u.City, u.DateOfBirth, l.Password);
         if (registerResult == 0)
             registerSuccess = true;
     }
     catch (Exception e)
     {
         errorInfo = Encoding.UTF32.GetBytes(e.Message + "\n" + e.StackTrace);
         errorLogDal = File.OpenWrite("E:\\Visual Studio Projects\\NKryptor\\ErrorLogs\\AccessLayers\\ErrorDal.log");
         errorLogDal.Write(errorInfo, 0, errorInfo.Length);
         errorLogDal.Close();
     }
     return registerSuccess;
 }
 public Task<bool> RegisterAsync(User u, LoginCredentials l)
 {
     return d.RegisterAsync(u,l);
 }
 public bool Login(LoginCredentials l)
 {
     bool loginSuccess = false;
     bool? loginResult = false;
     try
     {
         if (l.Contact.Equals(string.Empty))
         {
             loginResult = linqDc.FuncLogin(l.EmailAddress, null, l.Password);
             if (loginResult == true)
                 loginSuccess = true;
         }
         else
         if (l.EmailAddress.Equals(string.Empty))
         {
             loginResult = linqDc.FuncLogin(null, l.Contact, l.Password);
             if (loginResult == true)
                 loginSuccess = true;
         }
     }
     catch (Exception e)
     {
         errorInfo = Encoding.UTF32.GetBytes(e.Message + "\n" + e.StackTrace);
         errorLogDal = File.OpenWrite("E:\\Visual Studio Projects\\NKryptor\\ErrorLogs\\AccessLayers\\ErrorDal.log");
         errorLogDal.Write(errorInfo, 0, errorInfo.Length);
         errorLogDal.Close();
     }
     return loginSuccess;
 }
 public int GetMemberId(LoginCredentials l)
 {
     if (l.EmailAddress.Equals(string.Empty))
         return (int)linqDc.FuncGetMemberId(null, l.Contact);
     return ( int )linqDc.FuncGetMemberId(l.EmailAddress, null);
 }
 public Task<bool> ResetPasswordAsync(LoginCredentials l, string newPassword)
 {
     return d.ResetPasswordAsync(l, newPassword);
 }
 public Task<bool> LoginAsync(LoginCredentials l)
 {
     return d.LoginAsync(l);
 }
 public Task<int> GetMemberIdAsync(LoginCredentials l)
 {
     return d.GetMemberIdAsync(l);
 }
 public Task<bool> CheckAccountExistsAsync(LoginCredentials l)
 {
     return d.CheckAccountExistsAsync(l);
 }
 public Task<bool> UpdatePasswordAsync(LoginCredentials l, string oldPassword, string newPassword)
 {
     return d.UpdatePasswordAsync(l, oldPassword, newPassword);
 }
 public Task<bool> CheckAccountExistsAsync(LoginCredentials l)
 {
     return Task.Run<bool>(() => CheckAccountExists(l));
 }
 public Task<bool> LoginAsync(LoginCredentials l)
 {
     return Task.Run<bool>(() => Login(l));
 }
 public Task<int> GetMemberIdAsync(LoginCredentials l)
 {
     return Task.Run<int>(() => GetMemberId(l));
 }
 public Task<string> NameGiveLoginCredentialAsync(LoginCredentials l)
 {
     return Task.Run<string>(() => NameGivenLoginCredential(l));
 }
 public string NameGivenLoginCredential(LoginCredentials l)
 {
     string result = string.Empty;
     if (l.Contact.Equals(string.Empty))
         result = linqDc.FuncNameGivenLoginCredential(l.EmailAddress, string.Empty);
     if (l.EmailAddress.Equals(string.Empty))
         result = linqDc.FuncNameGivenLoginCredential(string.Empty, l.Contact);
     return result;
 }
 public Task<string> NameGiveLoginCredentialAsync(LoginCredentials l)
 {
     return d.NameGiveLoginCredentialAsync(l);
 }