Basic authentication
This commit is contained in:
@@ -21,7 +21,7 @@ namespace Scrummer.Code.Pages
|
||||
ChatControl chatControl = new ChatControl();
|
||||
chatControl.ID = "ctrChat";
|
||||
chatControl.IDBoard = _idBoard;
|
||||
chatControl.UserName = Convert.ToString(new Random().Next());
|
||||
chatControl.UserName = CurrentUser.Name;
|
||||
Controls.Add(chatControl);
|
||||
}
|
||||
}
|
||||
|
||||
71
Scrummer/Code/Pages/FrmLogin.cs
Normal file
71
Scrummer/Code/Pages/FrmLogin.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Web.UI.WebControls;
|
||||
using Scrummer.Code.BusinessLogic;
|
||||
using Scrummer.Code.Controls;
|
||||
|
||||
namespace Scrummer.Code.Pages
|
||||
{
|
||||
public class FrmLogin : PageCommon
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private CTextBox _txtNameEmail = new CTextBox { ID = "txtNameEmail", CssClassExtra = "width150px", AllowEmpty = false };
|
||||
private CTextBox _txtPassword = new CTextBox { ID = "txtPassword", CssClassExtra = "width150px", AllowEmpty = false, TextMode = TextBoxMode.Password };
|
||||
private CButton _btnLogin = new CButton { ID = "btnLogin"};
|
||||
|
||||
#endregion
|
||||
|
||||
#region Page life cycle
|
||||
|
||||
public FrmLogin()
|
||||
{
|
||||
MustBeAutenticated = false;
|
||||
Init += FrmLogin_Init;
|
||||
}
|
||||
|
||||
private void FrmLogin_Init(object sender, EventArgs e)
|
||||
{
|
||||
InitializeControls();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI Events
|
||||
|
||||
private void btnLogin_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (FormUtils.Controls_AreValid(Controls) == false) { return; }
|
||||
|
||||
if (Users.Current.User_Authenticate(_txtNameEmail.Text, _txtPassword.Text) == false)
|
||||
{
|
||||
_txtPassword.Text = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
Sessions.Current.Session_Init(Context, _txtNameEmail.Text);
|
||||
Response.Redirect(".");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void InitializeControls()
|
||||
{
|
||||
Title = "Login";
|
||||
var lblTitle = new CLabel { Text = "Login", Tag = "h2" };
|
||||
Controls.Add(lblTitle);
|
||||
|
||||
Controls.Add(FormUtils.CreateField("Name/Mail", _txtNameEmail));
|
||||
Controls.Add(FormUtils.CreateField("Password", _txtPassword));
|
||||
|
||||
Controls.Add(FormUtils.CreateField(String.Empty, _btnLogin));
|
||||
_btnLogin.Text = "Login";
|
||||
_btnLogin.Click += btnLogin_Click;
|
||||
|
||||
Controls.Add(FormUtils.CreateField(String.Empty, new HyperLink { Text = "Register user", NavigateUrl = "FrmRegister" }));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
122
Scrummer/Code/Pages/FrmRegister.cs
Normal file
122
Scrummer/Code/Pages/FrmRegister.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Web.UI.WebControls;
|
||||
using Scrummer.Code.BusinessLogic;
|
||||
using Scrummer.Code.Controls;
|
||||
using Scrummer.Code.Entities;
|
||||
|
||||
namespace Scrummer.Code.Pages
|
||||
{
|
||||
public class FrmRegister : PageCommon
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private Panel _pnlRegister = new Panel { ID = "pnlRegister" };
|
||||
private CTextBox _txtName = new CTextBox { ID = "txtName", CssClassExtra = "width150px", AllowEmpty = false };
|
||||
private CTextBox _txtEmail = new CTextBox { ID = "txtEmail", CssClassExtra = "width150px", AllowEmpty = false };
|
||||
private CTextBox _txtPassword1 = new CTextBox { ID = "txtPassword1", CssClass = "width150px", AllowEmpty = false, TextMode = TextBoxMode.Password };
|
||||
private CTextBox _txtPassword2 = new CTextBox { ID = "txtPassword2", CssClass = "width150px", AllowEmpty = false, TextMode = TextBoxMode.Password };
|
||||
private CButton _btnRegister = new CButton { ID = "btnRegister" };
|
||||
private CButton _btnExit = new CButton { ID = "btnExit" };
|
||||
private Panel _pnlSuccess = new Panel { ID = "pnlSuccess" };
|
||||
private CLabel _lblSuccess = new CLabel { ID = "lblSuccess" };
|
||||
private CButton _btnExitSuccess = new CButton { ID = "btnExitSuccess" };
|
||||
|
||||
#endregion
|
||||
|
||||
#region Page life cycle
|
||||
|
||||
public FrmRegister()
|
||||
{
|
||||
MustBeAutenticated = false;
|
||||
Init += FrmRegister_Init;
|
||||
}
|
||||
|
||||
void FrmRegister_Init(object sender, EventArgs e)
|
||||
{
|
||||
InitializeComponents();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI Events
|
||||
|
||||
void btnRegister_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (FormUtils.Controls_AreValid(Controls) == false) { return; }
|
||||
|
||||
// FIXME: Check Email
|
||||
|
||||
// Check password
|
||||
if (_txtPassword1.Text != _txtPassword2.Text)
|
||||
{
|
||||
_txtPassword1.MarkedInvalid = true;
|
||||
_txtPassword2.MarkedInvalid = true;
|
||||
_txtPassword1.Text = String.Empty;
|
||||
_txtPassword2.Text = String.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
User user = Users.Current.User_Set(_txtName.Text, _txtEmail.Text, _txtPassword1.Text);
|
||||
|
||||
_pnlRegister.Visible = false;
|
||||
_pnlSuccess.Visible = true;
|
||||
_lblSuccess.Text = String.Format("User {0} created sucessfully", user.Name);
|
||||
}
|
||||
|
||||
void btnExit_Click(object sender, EventArgs e)
|
||||
{
|
||||
Response.Redirect(".");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void InitializeComponents()
|
||||
{
|
||||
Title = "Register";
|
||||
var lblTitle = new CLabel { Text = "Register", Tag = "h2" };
|
||||
Controls.Add(lblTitle);
|
||||
|
||||
Controls.Add(_pnlRegister);
|
||||
|
||||
_pnlRegister.Controls.Add(FormUtils.CreateField("Name", _txtName));
|
||||
_txtName.PlaceHolder = "Name";
|
||||
|
||||
_pnlRegister.Controls.Add(FormUtils.CreateField("Email", _txtEmail));
|
||||
_txtEmail.PlaceHolder = "Email";
|
||||
|
||||
_pnlRegister.Controls.Add(FormUtils.CreateField("Password", _txtPassword1));
|
||||
_txtPassword1.PlaceHolder = "Password";
|
||||
|
||||
_pnlRegister.Controls.Add(FormUtils.CreateField(String.Empty, _txtPassword2));
|
||||
_txtPassword2.PlaceHolder = "Password";
|
||||
|
||||
_btnRegister.Text = "Register";
|
||||
_btnRegister.Click += btnRegister_Click;
|
||||
|
||||
_btnExit.Text = "Exit";
|
||||
_btnExit.Click += btnExit_Click;
|
||||
|
||||
Panel pnlButtons=new Panel();
|
||||
pnlButtons.Controls.Add(_btnRegister);
|
||||
pnlButtons.Controls.Add(_btnExit);
|
||||
_pnlRegister.Controls.Add(FormUtils.CreateField(String.Empty, pnlButtons));
|
||||
|
||||
|
||||
Controls.Add(_pnlSuccess);
|
||||
_pnlSuccess.Visible = false;
|
||||
|
||||
_pnlSuccess.Controls.Add(_lblSuccess);
|
||||
|
||||
_btnExitSuccess.Text = "Exit";
|
||||
_btnExitSuccess.Click += btnExit_Click;
|
||||
_pnlSuccess.Controls.Add(FormUtils.CreateField(String.Empty, _btnExitSuccess));
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ using System.Text;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.HtmlControls;
|
||||
using System.Web.UI.WebControls;
|
||||
using Scrummer.Code.BusinessLogic;
|
||||
using Scrummer.Code.Controls;
|
||||
using Scrummer.Code.Entities;
|
||||
|
||||
namespace Scrummer.Code.Pages
|
||||
{
|
||||
@@ -17,6 +19,9 @@ namespace Scrummer.Code.Pages
|
||||
private HtmlForm _form;
|
||||
private Panel _pnlContainer = new Panel();
|
||||
|
||||
private bool _mustBeAutenticated = true;
|
||||
private User _currentUser = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
@@ -26,16 +31,45 @@ namespace Scrummer.Code.Pages
|
||||
get { return _pnlContainer.Controls; }
|
||||
}
|
||||
|
||||
public bool MustBeAutenticated
|
||||
{
|
||||
get { return _mustBeAutenticated; }
|
||||
set { _mustBeAutenticated = value; }
|
||||
}
|
||||
|
||||
public User CurrentUser
|
||||
{
|
||||
get { return _currentUser; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Life cycle
|
||||
|
||||
public PageCommon()
|
||||
{
|
||||
PreInit += PageCommon_PreInit;
|
||||
Init += PageCommon_Init;
|
||||
PreRender += PageCommon_PreRender;
|
||||
}
|
||||
|
||||
void PageCommon_PreInit(object sender, EventArgs e)
|
||||
{
|
||||
Session session = Sessions.Current.Session_GetCurrent(Context);
|
||||
if (session != null)
|
||||
{
|
||||
_currentUser = Users.Current.User_GetByName(session.UserName);
|
||||
if (_mustBeAutenticated)
|
||||
{
|
||||
Sessions.Current.Session_SetCookie(Context, session);
|
||||
}
|
||||
}
|
||||
if (_currentUser == null && _mustBeAutenticated)
|
||||
{
|
||||
Response.Redirect("FrmLogin");
|
||||
}
|
||||
}
|
||||
|
||||
void PageCommon_Init(object sender, EventArgs e)
|
||||
{
|
||||
CreateControls();
|
||||
|
||||
Reference in New Issue
Block a user