예제 #1
0
        public bool IsValidSession(DbConnect con, string token, int user_id)
        {
            if (!App.CheckToken)
            {
                return(true);
            }
            DynamicDictionary tokenDetail = GetTokenDetail(token, user_id);

            if (tokenDetail == null || tokenDetail.GetCount() == 0)
            {
                return(false);
            }
            if (tokenDetail.ContainsKey("expire_datetime"))
            {
                if (!String.IsNullOrEmpty(tokenDetail["expire_datetime"].ToString()))
                {
                    DateTime expiryDate   = Convert.ToDateTime(tokenDetail["expire_datetime"]);
                    DateTime current_date = DateTime.Now;
                    TimeSpan difference   = expiryDate - current_date;
                    if (difference.TotalMinutes < 0)
                    {
                        Status = AuthorizationStatus.SessionExpired;
                        return(false);
                    }
                    else
                    {
                        SessionData.client_id = tokenDetail.GetValueAsInt("client_id");
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #2
0
        public virtual BangoCommand GetSearchCommand(SearchScenario scenario, DbConnect con, BangoCommand cmd, DynamicDictionary data_param, string selectClause, string orderByClause, int page = -1, int pageSize = 20, bool count = false, string tableAlias = null, string scenarioOthers = null)
        {
            TableDetailAttribute tableDetail = _model.GetTableDetail();
            //clear the params whic are empty or null
            List <string> keys = new List <string>(data_param.KeyList.Cast <String>());

            foreach (string key in keys)
            {
                object value = data_param.GetValue(key);
                if (value == null || data_param.GetValueAsString(key).Length == 0)
                {
                    data_param.Remove(key);
                }
            }

            //BangoCommand cmd = GetSearchCommandTemplate(selectClause, count, tableAlias);
            //cmd.Sql.AppendLine("FROM " + model.GetTableName());
            IDbExpression dbExp = App.Container.GetInstance <IDbExpression>();

            if (data_param.GetCount() == 0)
            {
                return(cmd);
            }

            string append = DbServiceUtility.GetTableAliasForColumn(tableAlias);

            if (!(scenario == SearchScenario.TreeNode && count == false))
            {
                //check & adding delete flag check sql
                DbServiceUtility.BindDeleteParameter(cmd, _model, tableAlias);

                if (CheckClientID)
                {
                    DbServiceUtility.BindClientIdParameter(cmd, _model, tableAlias, DisplayMasterDataFromSystem);
                }

                //add remaining default search criteria

                cmd = BeforeBindingParameter(scenario, con, cmd, data_param, count, tableAlias);
                cmd = DbServiceUtility.BindParameters(cmd, _model, data_param, tableAlias);
                cmd = AfterBindingParameter(scenario, con, cmd, data_param, count, tableAlias);

                //check & adding order by clause
                if (count == false)
                {
                    cmd = BeforeBindingOrderBy(scenario, con, cmd, data_param, count, tableAlias);
                    cmd = DbServiceUtility.BindOrderBy(cmd, orderByClause);
                    cmd = AfterBindingOrderBy(scenario, con, cmd, data_param, count, tableAlias);
                    cmd = DbServiceUtility.BindPagination(cmd, page, pageSize);
                }
            }
            return(cmd);
        }
        protected bool AuthenticationFromDB(HttpActionContext actionContext, string token, int user_id)
        {
            if (!App.CheckToken)
            {
                return(true);
            }
            IAuthService      authSrvc    = App.Container.GetInstance <Rbac.IAuthService>();
            DynamicDictionary tokenDetail = authSrvc.GetTokenDetail(token, user_id);

            if (tokenDetail == null || tokenDetail.GetCount() == 0)
            {
                Status = AuthorizationStatus.NotLoggedIn;
                return(false);
            }
            if (tokenDetail.ContainsKey("expire_datetime"))
            {
                if (!String.IsNullOrEmpty(tokenDetail["expire_datetime"].ToString()))
                {
                    DateTime expiryDate   = Convert.ToDateTime(tokenDetail["expire_datetime"]);
                    DateTime current_date = DateTime.Now;
                    TimeSpan difference   = expiryDate - current_date;
                    if (difference.TotalMinutes < 0)
                    {
                        Status = AuthorizationStatus.SessionExpired;
                        return(false);
                    }
                    else
                    {
                        int?session_id = tokenDetail.GetValueAsInt("id");
                        _client_id            = (int)tokenDetail.GetValueAsInt("client_id");
                        SessionData.client_id = _client_id;
                        DynamicDictionary data_param = new DynamicDictionary();
                        data_param.Add("expire_datetime", AuthService.GetExpirtyDateTime(DateTime.Now));
                        data_param.Add("id", session_id);
                        SessionLogService logSrvc = new SessionLogService();
                        logSrvc.Update(session_id, data_param);
                        Status = AuthorizationStatus.Authorized;
                        return(true);
                    }
                }
            }
            return(false);
        }