protected override void OnInit(EventArgs e) { base.OnInit(e); if (DaemonHttpContext.LoggedInParticipant == null) { RelyingPartyLogic.User user = Database.LoggedInUser; if (user != null) { foreach (AuthenticationToken token in from t in Database.DataContext.AuthenticationTokens where t.User.UserId == user.UserId select t) { if (token.ClaimedIdentifier != null) { Participant participant = ParticipantLogic.AttachParticipantProfileToOpenIdIdentity(user.UserId, token.ClaimedIdentifier); DaemonHttpContext.LoggedInParticipant = participant; } } } } if (DaemonHttpContext.LoggedInParticipant != null) { Participant participant = DaemonHttpContext.LoggedInParticipant; ParticipantLogic.GetLoginSecret(participant); Page.Items["goto"] = Request["goto"]; Page.Items["participantIdentifier"] = participant.ParticipantId.ToString("N"); Page.Items["loginSecret"] = participant.LoginSecret; } Response.Cache.SetCacheability(HttpCacheability.NoCache); }
private static AuthenticationToken ProcessUserLogin(string claimedIdentifier, string friendlyIdentifier, ClaimsResponse claims, Token samlToken, bool trustedEmail) { // Create an account for this user if we don't already have one. AuthenticationToken openidToken = Database.DataContext.AuthenticationTokens.FirstOrDefault(token => token.ClaimedIdentifier == claimedIdentifier); if (openidToken == null) { // this is a user we haven't seen before. User user = new User(); openidToken = new AuthenticationToken { ClaimedIdentifier = claimedIdentifier, FriendlyIdentifier = friendlyIdentifier, }; user.AuthenticationTokens.Add(openidToken); // Gather information about the user if it's available. if (claims != null) { if (!string.IsNullOrEmpty(claims.Email)) { user.EmailAddress = claims.Email; user.EmailAddressVerified = trustedEmail; } if (!string.IsNullOrEmpty(claims.FullName)) { if (claims.FullName.IndexOf(' ') > 0) { user.FirstName = claims.FullName.Substring(0, claims.FullName.IndexOf(' ')).Trim(); user.LastName = claims.FullName.Substring(claims.FullName.IndexOf(' ')).Trim(); } else { user.FirstName = claims.FullName; } } } else if (samlToken != null) { string email, givenName, surname; if (samlToken.Claims.TryGetValue(ClaimTypes.Email, out email)) { user.EmailAddress = email; user.EmailAddressVerified = trustedEmail; } if (samlToken.Claims.TryGetValue(ClaimTypes.GivenName, out givenName)) { user.FirstName = givenName; } if (samlToken.Claims.TryGetValue(ClaimTypes.Surname, out surname)) { user.LastName = surname; } } Database.DataContext.AddToUsers(user); } else { openidToken.UsageCount++; openidToken.LastUsedUtc = DateTime.UtcNow; } return openidToken; }
/// <summary> /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToUsers(User user) { base.AddObject("Users", user); }
/// <summary> /// Create a new User object. /// </summary> /// <param name="emailAddressVerified">Initial value of the EmailAddressVerified property.</param> /// <param name="createdOnUtc">Initial value of the CreatedOnUtc property.</param> /// <param name="userId">Initial value of the UserId property.</param> public static User CreateUser(global::System.Boolean emailAddressVerified, global::System.DateTime createdOnUtc, global::System.Int32 userId) { User user = new User(); user.EmailAddressVerified = emailAddressVerified; user.CreatedOnUtc = createdOnUtc; user.UserId = userId; return user; }