if (myAccountInfo != null) {
HttpContext.Current.Session[ACCOUNT_KEY] = myAccountInfo;
// Determine where to redirect the user back too
// If they came in from the home page, take them to a similar page
if (FormsAuthentication.GetRedirectUrl(userId, false).EndsWith(URL_DEFAULT)) {
}else {
// Login has failed so return false
return false;
}
}
public bool CreateAccount(AccountInfo newAccountInfo){
try {
// Creata a new business logic tier
Account account = new Account();
// Call the insert method
account.Insert(newAccountInfo);
// Store the data in session state and store the authenticated cookie
HttpContext.Current.Session[ACCOUNT_KEY] = newAccountInfo;
FormsAuthentication.SetAuthCookie(newAccountInfo.UserId, false);
//Finally forward to the welcome page
HttpContext.Current.Response.Redirect(URL_ACCOUNTCREATE, true);
}catch {
return false;
}
return true;
}
/// <summary>
/// A method to process an updated account
/// </summary>
/// <param name="updatedAccountInfo">Updated account information</param>
public void UpdateAccount(AccountInfo updatedAccountInfo){
// Create the business logic tier
Account account = new Account();
// Call the udpate method
account.Update(updatedAccountInfo);
//Store the update info back in session state
HttpContext.Current.Session[ACCOUNT_KEY] = updatedAccountInfo;
//Redirect the user to the my account page
HttpContext.Current.Response.Redirect(URL_ACCOUNTUPDATE, true);
}
/// <summary>
/// Retrieves the account information for a customer who has already logged in
/// The method assume the account information is in session state
/// If it can't find it the function will direct the user to login
/// </summary>
/// <returns>The account info for the currently logged in user</returns>
public AccountInfo GetAccountInfo(bool required){
AccountInfo myAccount = (AccountInfo)HttpContext.Current.Session[ACCOUNT_KEY];
if (myAccount == null){
if(required){
HttpContext.Current.Response.Redirect(URL_SIGNIN, true);
}
return null;
}else{
return myAccount;
}
}
/// <summary>
/// Retrieves favourtie category of a customer if we know who they are
/// The method assume the account information is in session state
/// </summary>
/// <returns>The customers favourite category</returns>
public string GetFavouriteCategory(){