public virtual DomainAccessGuard.Session GetValidUser(string paramValue, ItemContextParameters parameters, IConversation conversation) { var username = paramValue.Replace(" ", ""); if (string.IsNullOrEmpty(username)) { return(null); } string regex = @"^(\w[\w\s]*)([\\]{1})(\w[\w\s\.\@]*)$"; Match m = Regex.Match(username, regex); if (string.IsNullOrEmpty(m.Value)) { return(null); } DomainAccessGuard.Session userSession = null; if (User.Exists(username)) { userSession = AuthenticationWrapper.GetDomainAccessSessions().FirstOrDefault( s => string.Equals(s.UserName, username, StringComparison.OrdinalIgnoreCase)); } return(userSession); }
public IParameterResult GetParameter(string paramValue, IConversationContext context) { if (string.IsNullOrWhiteSpace(paramValue)) { return(ResultFactory.GetFailure(ParamMessage)); } var error = Translator.Text("Chat.Parameters.UserParameterValidationError"); var username = paramValue.Replace(" ", ""); if (string.IsNullOrEmpty(username)) { return(ResultFactory.GetFailure(error)); } string regex = @"^(\w[\w\s]*)([\\]{1})(\w[\w\s\.\@]*)$"; Match m = Regex.Match(username, regex); if (string.IsNullOrEmpty(m.Value)) { return(ResultFactory.GetFailure(error)); } DomainAccessGuard.Session userSession = null; if (Sitecore.Security.Accounts.User.Exists(username)) { userSession = AuthenticationWrapper.GetDomainAccessSessions().FirstOrDefault( s => string.Equals(s.UserName, username, StringComparison.OrdinalIgnoreCase)); } return(userSession == null ? ResultFactory.GetFailure(error) : ResultFactory.GetSuccess(username, userSession)); }
private static LoggedInUser GetSitecoreUser(DomainAccessGuard.Session session) { var sitecoreUser = Security.Accounts.User.FromName(session.UserName, false); return(new LoggedInUser( session.SessionID, session.UserName, session.Created, session.LastRequest, sitecoreUser.IsAdministrator)); }
public Account Get(string username) { Account model = new Account(); SettingsController settings = new SettingsController(); if (!string.IsNullOrEmpty(username)) { model.User = Sitecore.Security.Accounts.User.FromName(username, false); if (model.User != null) { model.Valid = true; model.Admin = model.User.IsAdministrator; model.Name = model.User.Profile != null ? model.User.Profile.Name : username; MembershipUser mu = Membership.GetUser(username); if (model.User.Profile != null) { Sitecore.Diagnostics.Log.Warn("Found user (" + username + ") online through last activity date (" + model.User.Profile.LastActivityDate.ToShortDateString() + " " + model.User.Profile.LastActivityDate.ToShortTimeString() + ")", this); model.LoggedIn = model.User.Profile.LastActivityDate.AddMinutes(settings.GetIdleTimeout()) <= DateTime.Now; } else if (mu != null && mu.IsOnline) { Sitecore.Diagnostics.Log.Warn("Found user (" + username + ") online through Membership User", this); model.LoggedIn = true; } else { DomainAccessGuard.Session userSession = DomainAccessGuard.Sessions.Find(session => session.UserName == username); if (userSession == null) { Sitecore.Diagnostics.Log.Warn("Found user (" + username + ") logged out through no DomainAccessGuard session", this); model.LoggedIn = false; } else { Sitecore.Diagnostics.Log.Warn("Found user (" + username + ") online through DomainAccessGuard last request " + userSession.LastRequest.ToString(), this); model.LoggedIn = userSession.LastRequest.AddMinutes(settings.GetIdleTimeout()) <= DateTime.Now; } } } } return(model); }