コード例 #1
0
 private LoginUser GetUserByName(string userName)
 {
     AuthenticationLib.AuthService.Login log = ControllerAuth.GetUser(userName);
     return(new LoginUser
     {
         UserID = log.UserID,
         Name = log.UserName,
         LastName = log.LastName,
         FirstName = log.FirstName,
         Email = log.Email,
         UserType = log.UserType,
         Roles = log.ListOjectKey
     });
 }
コード例 #2
0
        public LoginUser Login(string userName, string password, bool isPersistent, string customData)
        {
            try
            {
                AuthenticationLib.AuthService.Login log = ControllerAuth.UserLogin(userName, password);
                if (log.UserID != -1)
                {
                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                        /* version */ 1,
                        userName,
                        DateTime.Now, DateTime.Now.AddDays(1),
                        isPersistent,
                        string.Empty,
                        FormsAuthentication.FormsCookiePath);

                    string     encryptedTicket = FormsAuthentication.Encrypt(ticket);
                    HttpCookie authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

                    if (ticket.IsPersistent)
                    {
                        authCookie.Expires = ticket.Expiration;
                    }

                    HttpContextBase httpContext = (HttpContextBase)ServiceContext.GetService(typeof(HttpContextBase));
                    httpContext.Response.Cookies.Add(authCookie);

                    return(new LoginUser
                    {
                        UserID = log.UserID,
                        Name = log.UserName,
                        LastName = log.LastName,
                        FirstName = log.FirstName,
                        Email = log.Email,
                        UserType = log.UserType,
                        Roles = log.ListOjectKey
                    });
                }
                return(DefaultLoginUser);
            }
            catch (Exception ex)
            {
                Exception actualException = ex;
                while (actualException.InnerException != null)
                {
                    actualException = actualException.InnerException;
                }
                throw actualException;
            }
        }
コード例 #3
0
        private LoginUser GetUserByName(string userName)
        {
            AuthenticationLib.AuthService.Login log = ControllerAuth.GetUser(userName);
            LoginUser result = new LoginUser
            {
                UserID    = log.UserID,
                Name      = log.UserName,
                LastName  = log.LastName,
                FirstName = log.FirstName,
                Email     = log.Email,
                UserType  = log.UserType,
                Roles     = log.ListOjectKey,
                Settings  = new Dictionary <string, string>()
            };

            foreach (var item in ObjectContext.Vlu_UserSettings.Where(c => c.TaiKhoanID == result.UserID))
            {
                result.Settings.Add(item.KeySetting, item.ValueSetting);
            }
            return(result);
        }