/// <summary> /// Authorize the users access from application (Logout) /// </summary> public static void Authorize() { try { var ticket = ManageUserModelHelper.GetFormsAuthenticationTicket(); if (ticket != null) { var idKey = ticket.IdKey(); if (idKey != Guid.Empty) { using (var db = new DbContextHelper()) { User user = ManageUserModelHelper.GetUser(db, idKey); if (user != null) { user.UserStatusEnum = UserStatus.Offline; db.SaveChanges(); } } //end using } //end if } //end if FormsAuthentication.SignOut(); } catch (Exception ex) { LogHelper.LogFatalError("UserModelHelper.Authorize", ex); throw ex; } }
/// <summary> /// Authorize the current user on the site. Authenication occurs via Facebook app (signin) /// </summary> /// <param name="model">User model</param> /// <param name="status">status of authorizing the user</param> /// <param name="code">Facebook Oauth code used to retrieve a Facebook access token</param> /// <returns></returns> /// <remarks>Requires the code to be set on the model. This is used to retrieve a Facebook access token</remarks> public static bool Authorize(this UserModel model, string code, out Status status) { try { using (var db = new DbContextHelper()) { // TODO: Validate the access token var user = ManageUserModelHelper.GetUser(db, idKey: model.IdKey, email: model.Email, screenName: model.ScreenName, facebookId: model.FacebookId); if (user == null) { return(model.Register(out status)); } user.AccessToken = model.AccessToken; user.LastAccessed = DateTime.Now; user.UserStatusEnum = UserStatus.Online; db.SaveChanges(); // Save the user basic information model.Id = user.Id; model.IdKey = user.IdKey; model.ScreenName = user.ScreenName; model.FirstName = user.FirstName; model.LastName = user.LastName; model.UserStatus = user.UserStatusEnum; model.Roles = user.Roles.ToList().GetRoleModelsFromRoles(); model.CreateAuthorizationTicket(); status = Status.Success; return(true); } } catch (Exception ex) { LogHelper.LogFatalError("FacebookHelper.Authorize", ex); status = Status.SystemException; } return(false); }
/// <summary> /// Authorize the current user on the site. Authenication occurs via Facebook app /// </summary> /// <param name="model"></param> /// <param name="status"></param> /// <returns></returns> public static bool Authorize(this UserModel model, out Status status) { try { using (var db = new DbContextHelper()) { var user = ManageUserModelHelper.GetUser(db, model.IdKey, model.Email); if (user == null) { status = Status.InvalidLoginPassword; return(false); } user.AccessToken = model.AccessToken; user.LastAccessed = DateTime.Now; user.UserStatusEnum = UserStatus.Online; db.SaveChanges(); // Save the user basic information model.Id = user.Id; model.IdKey = user.IdKey; model.ScreenName = user.ScreenName; model.FirstName = user.FirstName; model.LastName = user.LastName; model.UserStatus = user.UserStatusEnum; model.Roles = user.Roles.ToList().GetRoleModelsFromRoles(); model.CreateAuthorizationTicket(); status = Status.Success; return(true); } } catch (Exception ex) { LogHelper.LogFatalError("UserModelHelper.Authorize", ex); status = Status.SystemException; } return(false); }