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;
		}
Exemple #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();
		}
	}
	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();
		}
	}