|
If you have an Active / Inactive flag in your application’s user table and would like only active
users to login, you can accomplish this in multiple ways using Iron Speed Designer.
Use a Database View
The simplest way is to create a database view in your database that only contains the Active users
and excludes Inactive users. Then you can use this database view as the User "table" in the Role-Based
Security Wizard in Iron Speed Designer.
Use a Code Customization
Step 1: In Iron Speed Designer, create an application using a database table, such as the Orders
table in Northwind.
Step 2: Enable role-based security using the Role-Based Security Wizard in Iron Speed Designer.
Step 3: Select “Grant Access only to signed-in users” in the Security tab in the Properties dialog
for your web page, such as ShowOrdersTablePage.aspx.
Step 4: Override the Login() method in SignIn_Control.Control.vb or .cs using a code customization.
The Login() method is defined in BaseSignIn_Control.vb or .cs.
For .NET Framework 1.1, SignIn_Control.Control.vb or .cs is in:
|
<Application>\Shared\SignIn_Control.Controls.cs
|
For.NET Framework 2.0, SignIn_Control.Control.vb or .cs is in:
|
<Application>App_Code\Shared\SignIn_Control.Control.vb or .cs
|
Your code customization might look something like:
C#:
using MyApp12.<namespace of your User Table >;
public override void Login(bool redirectOnSuccess)
{
string strUserName = this.UserName.Text;
string strPassword = this.Password.Text;
// Check if user has entered the user name and password.
if (((strUserName != "") && (strPassword != "")))
{
// Construct a WHERE clause to retrieve the record that
// matches the specified username
string colName = UsersTable.Instance.UserNameColumn.UniqueName;
string whereStr = colName + "= '" + strUserName + "'";
UsersRecord rec = UsersTable.GetRecord(whereStr);
// Check if this is a valid user and is active
if (((rec == null) || (!rec.Active)))
{
// Display an error message and return
// For testing purpose, you can change the message with
// different string to check if it works
ProcessLoginFailed("Invalid login information.Please enter a valid user name.",
strUserName);
return;
}
// Otherwise, fall through to call the Base Class's Login function.
}
base.Login(redirectOnSuccess);
}
|
Visual Basic .NET:
Imports MyApp.<Namespace of your User Table>
Public Overloads Overrides Sub Login(ByVal bRedirectOnSuccess As Boolean)
Dim strUserName As String = Me.UserName.Text
Dim strPassword As String = Me.Password.Text
'Check if user has entered the user name and password.
If (strUserName <> "" AndAlso strPassword <> "") Then
' Construct a WHERE clause to retrieve the record that
' matches the specified username
Dim columnName As String = UsersTable.Instance.UserNameColumn.UniqueName
Dim whereStr As String = columnName & "= '" & strUserName & "'"
Dim rec As UsersRecord = UsersTable.GetRecord(whereStr)
' Check to see if this is a valid user and is active
If ((IsNothing(rec)) OrElse Not(rec.Active)) Then
' Display an error message and return
' For testing purpose, you can change ERR_INVALID_LOGIN_INFO
' with a different string to check if it works
ProcessLoginFailed(ERR_INVALID_LOGIN_INFO, strUserName)
Return
End If
' Otherwise fall through to call the base class's Login function.
End If
MyBase.Login(bRedirectOnSuccess)
End Sub
|
|