예제 #1
0
        public APIPrincipal(string email)
        {
            i1 = 0;
            i2 = 0;

            //Log.Info( "calling WS to get rights...");

            string msg = new UserManager().getRightsByEmail(email, GlobalStatics.ProductId, out i1, out i2);
            if (msg.Length == 0)
            {
                this.identity = new APIIdentity(email);
            }
            else
            {
                //Log.WriteLog(Category.General, Level.Error, email + "|" + GlobalStatics.ProductId + "|" + msg);
            }
            APIPrincipal.fillPermissionArray(i1, i2, out this.m1, out this.m2);
        }
예제 #2
0
        public static APIPrincipal Login(string email, string pwd, out string msg)
        {
            APIPrincipal p = null;
            bool[] m1 = new bool[32];
            bool[] m2 = new bool[32];
            int i1, i2;
            long iid;
            msg = string.Empty;
            //Log.Info( "calling WS to verify login and get rights...");
            string gid = new UserManager().Login(email, pwd, GlobalStatics.ProductId, out i1, out i2, out iid, out msg);
            APIPrincipal.fillPermissionArray(i1, i2, out m1, out m2);

            if (gid.Length > 0)
                p = new APIPrincipal(gid, email, m1, m2);
            else
            {
                //Log.Error(email + ", Message: " + msg);
            }
            return p;
        }
예제 #3
0
        private void GetPrincipal()
        {
            try
            {
                DateTime currentTime = DateTime.Now;
                HttpCookie cookie;
                cookie = HttpContext.Current.Request.Cookies[GlobalStatics.CookieName];
                #region If is local machine, use localuser
                if (HttpContext.Current.Request.IsLocal)
                {
                    bool[] m1 = new bool[32];
                    bool[] m2 = new bool[32];
                    for (int i = 0; i < m1.Length; i++)
                    {
                        m1[i] = true;
                        m2[i] = true;
                    }

                    _APIUserPrincipal = new APIPrincipal(LocalUserId, LocalUserLoginEmail, m1, m2);
                    HttpContext.Current.User = _APIUserPrincipal;

                    UserManager userManager = new UserManager();
                    _User = userManager.GetUserbyId(ConfigurationManager.AppSettings["LocalUserId"]);
                    _User.Roles = new UserManager().GetUserRoles(ConfigurationManager.AppSettings["LocalUserId"]);
                    this.SavePrin(_APIUserPrincipal);
                    this.CheckPermittedRole();
                    //this.CheckEnvironment();
                    return;
                }

                #endregion disable EdgarAuth for special needs

                //Log.Debug(cookie);

                GlobalStatics.MonitorProcessTime("First log", ref currentTime, DateTime.Now);
                if (cookie != null)
                {
                    _User = GetUserFromCookie();
                    if (_User != null)
                    {
                        this.CheckPermittedRole();
                        //this.CheckEnvironment();
                    }
                    else
                    {
                        this.GoToLogin();
                        //Log.Error("Failed to get auth info from cookie.");
                    }
                }
                else
                {
                    this.GoToLogin();
                }
                GlobalStatics.MonitorProcessTime("EndAuthenticate", ref currentTime, DateTime.Now);
            }
            catch (Exception ex)
            {
                //Log.Error(ex);
                throw ex;
            }
        }
예제 #4
0
 protected virtual User GetUserFromCookie()
 {
     HttpCookie cookie = HttpContext.Current.Request.Cookies[GlobalStatics.CookieName];
     if (cookie == null)
         return null;
     if (cookie["API"] == null)
         return null;
     Dictionary<string, string> authKeyPair = GlobalStatics.ParseCookie(cookie);
     if (authKeyPair.Keys.Count == 0)
         return null;
     if (!authKeyPair.ContainsKey("LoginEmail"))
         return null;
     User user = new UserManager().GetUserByEmail(authKeyPair["LoginEmail"]);
     user.Password = authKeyPair["Password"];
     user.Roles = new UserManager().GetUserRoles(user.UserId);
     return user;
 }
예제 #5
0
 private void Process4ExistedGLUser(ref string msg, ref bool isLoginSuccess)
 {
     if (new UserManager().GetUserByEmail(_UserInfo.LoginEmail) != null)
     {
         int effectedRow = new UserManager().UpdateUserIdByEmail(_UserInfo.LoginEmail, _APIUserPrincipal.Guid);
         if (effectedRow <= 0)
         {
             //Log.Error("No data effected at Id:" + _UserInfo.LoginEmail);
             msg = "Failed to update account in Equity API Database.";
             isLoginSuccess = false;
         }
         else
         {
             _UserInfo = new UserManager().GetUserbyId(_APIUserPrincipal.Guid);
             if (_UserInfo != null)
             {
                 _UserInfo.Roles = new UserManager().GetUserRoles(this._APIUserPrincipal.Guid);
                 _UserInfo.Password = _Password;
                 //UpdateUserNotificationMessage(_UserInfo.UserId);
                 isLoginSuccess = true;
             }
             else
             {
                 isLoginSuccess = false;
                 msg = "Failed to get User entity by UserId.";
             }
         }
     }
     else
     {
         msg = "Your account was not existed in Equity API Database.";
         isLoginSuccess = false;
     }
 }
예제 #6
0
 private void CheckLoginedUser(ref string msg, ref bool isLoginSuccess, ref DateTime startTime)
 {
     User existedUser = new UserManager().GetUserbyId(this._APIUserPrincipal.Guid);
     GlobalStatics.MonitorProcessTime("Get User from DB", ref startTime, DateTime.Now);
     if (existedUser != null)
     {
         Process4ExistedAPIUser(ref msg, ref isLoginSuccess, ref startTime, existedUser);
     }
     else
     {
         Process4ExistedGLUser(ref msg, ref isLoginSuccess);
     }
 }