コード例 #1
0
        public ActionResult Login()
        {
            try
            {
                GetUserProfileObject PostDataArrived = CS.GetPostData <GetUserProfileObject>(this.Request);

                ConnectionStringSettings connectionStringSetting = ConfigurationManager.ConnectionStrings["ISTATWebClientSSO"];
                if (connectionStringSetting == null || string.IsNullOrEmpty(connectionStringSetting.ConnectionString))
                {
                    throw new Exception("ConnectionString not set");
                }

                if (PostDataArrived.IsSuperAdmin)
                {
                    UserRolesEnum ruolo = UserRolesEnum.Administrator;
                    PostDataArrived.UserRole = new UserRoleObject()
                    {
                        RoleId = (int)ruolo, Role = ruolo.ToString()
                    };
                }
                else
                {
                    connectionStringSetting = ConfigurationManager.ConnectionStrings["ISTATWebClientConnection"];
                    ProfileWidget pw = new ProfileWidget(connectionStringSetting.ConnectionString);
                    PostDataArrived.UserRole = pw.GetRole(PostDataArrived);
                }

                Session[ProfileSession] = PostDataArrived;
                return(CS.ReturnForJQuery(new JavaScriptSerializer().Serialize(PostDataArrived)));
            }
            catch (Exception ex)
            {
                return(CS.ReturnForJQuery(ex.Message));
            }
        }
コード例 #2
0
        public ActionResult ModUserRole()
        {
            GetUserProfileObject PostDataArrived = CS.GetPostData <GetUserProfileObject>(this.Request);

            if (Session[ProfileSession] == null)
            {
                throw new Exception("No logged user");
            }
            GetUserProfileObject LoggedUser = (GetUserProfileObject)Session[ProfileSession];

            if (LoggedUser.UserRole != null && (UserRolesEnum)LoggedUser.UserRole.RoleId != WidgetComplements.Model.Enum.UserRolesEnum.Administrator)
            {
                throw new Exception("No Administration user");
            }

            ConnectionStringSettings connectionStringSetting = ConfigurationManager.ConnectionStrings["ISTATWebClientConnection"];

            if (connectionStringSetting == null || string.IsNullOrEmpty(connectionStringSetting.ConnectionString))
            {
                throw new Exception("ConnectionString not set");
            }

            ProfileWidget pw = new ProfileWidget(connectionStringSetting.ConnectionString);

            PostDataArrived = pw.ChangeRole(PostDataArrived);

            return(CS.ReturnForJQuery(new JavaScriptSerializer().Serialize(PostDataArrived)));
        }
コード例 #3
0
        public GetUserProfileObject ChangeRole(GetUserProfileObject PostDataArrived)
        {
            try
            {
                if (PostDataArrived == null || string.IsNullOrEmpty(PostDataArrived.UserCode))
                {
                    throw new Exception("Input Error");
                }


                string sqlquery = string.Format("select count(*) from UserRoles where UserCode='{0}'", PostDataArrived.UserCode.Replace("'", "''"), PostDataArrived.UserRole.RoleId);
                //string

                Sqlconn.Open();
                try
                {
                    DataTable dtres = new DataTable();
                    using (SqlCommand comm = new SqlCommand(sqlquery, Sqlconn))
                    {
                        int conta = Convert.ToInt32(comm.ExecuteScalar());
                        if (conta > 0)
                        {
                            sqlquery = string.Format("Update UserRoles set RoleId={1} where UserCode='{0}'", PostDataArrived.UserCode.Replace("'", "''"), PostDataArrived.UserRole.RoleId);
                        }
                        else
                        {
                            sqlquery = string.Format("INSERT INTO UserRoles (UserCode, RoleId) VALUES ('{0}',{1})", PostDataArrived.UserCode.Replace("'", "''"), PostDataArrived.UserRole.RoleId);
                        }
                    }
                    using (SqlCommand comm = new SqlCommand(sqlquery, Sqlconn))
                    {
                        int mod = comm.ExecuteNonQuery();
                        if (mod <= 0)
                        {
                            throw new Exception("User not modified");
                        }
                    }

                    return(PostDataArrived);
                }
                catch (Exception) { throw; }
                finally
                {
                    Sqlconn.Close();
                }
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
                throw new Exception(string.Format(ErrorOccuredMess, ex.Message));
            }
        }
コード例 #4
0
 public ActionResult IsLogin()
 {
     try
     {
         GetUserProfileObject PostDataArrived = CS.GetPostData <GetUserProfileObject>(this.Request);
         Session[ProfileSession] = PostDataArrived;
         return(CS.ReturnForJQuery(new JavaScriptSerializer().Serialize(PostDataArrived)));
     }
     catch (Exception ex)
     {
         return(CS.ReturnForJQuery(ex.Message));
     }
 }
コード例 #5
0
        public UserRoleObject GetRole(GetUserProfileObject PostDataArrived)
        {
            try
            {
                if (PostDataArrived == null || string.IsNullOrEmpty(PostDataArrived.UserCode))
                {
                    throw new Exception("Input Error");
                }

                string sqlquery = string.Format("Select * from UserRoles where UserCode='{0}'", PostDataArrived.UserCode.Replace("'", "''"));

                Sqlconn.Open();
                try
                {
                    DataTable dtres = new DataTable();
                    using (SqlCommand comm = new SqlCommand(sqlquery, Sqlconn))
                    {
                        using (SqlDataAdapter da = new SqlDataAdapter(comm))
                        {
                            da.Fill(dtres);
                        }
                    }
                    UserRolesEnum ruolo = UserRolesEnum.User;
                    if (dtres != null && dtres.Rows.Count > 0)
                    {
                        int RoleCode = Convert.ToInt32(dtres.Rows[0]["RoleId"].ToString());
                        ruolo = (UserRolesEnum)RoleCode;
                    }

                    return(new UserRoleObject()
                    {
                        RoleId = (int)ruolo, Role = ruolo.ToString()
                    });
                }
                catch (Exception) { throw; }
                finally
                {
                    Sqlconn.Close();
                }
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
                throw new Exception(string.Format(ErrorOccuredMess, ex.Message));
            }
        }
コード例 #6
0
        public ActionResult GetUserList()
        {
            /*string SingleSignOnConf;
             * using (Stream receiveStream = this.Request.InputStream)
             *  using (StreamReader readStream = new StreamReader(receiveStream, this.Request.ContentEncoding))
             *  {
             *      SingleSignOnConf = readStream.ReadToEnd();
             *  }
             */
            if (Session[ProfileSession] == null)
            {
                throw new Exception("No logged user");
            }
            GetUserProfileObject LoggedUser = (GetUserProfileObject)Session[ProfileSession];

            if (LoggedUser.UserRole != null && (UserRolesEnum)LoggedUser.UserRole.RoleId != WidgetComplements.Model.Enum.UserRolesEnum.Administrator)
            {
                throw new Exception("No Administration user");
            }

            ConnectionStringSettings connectionStringSetting = ConfigurationManager.ConnectionStrings["ISTATWebClientConnection"];

            if (connectionStringSetting == null || string.IsNullOrEmpty(connectionStringSetting.ConnectionString))
            {
                throw new Exception("ConnectionString not set");
            }

            ProfileWidget pw = new ProfileWidget(connectionStringSetting.ConnectionString);

            //Prendo tutti gli utenti su SingleSignON
            //Prendo tutti i Ruoli dal localDB
            //var JsonRet = new { UserList = pw.GetUserList(SingleSignOnConf), Roles = pw.GetRoles() };

            SingleSignONService ssoService = new SingleSignONService();
            var JsonRet = new { UserList = ssoService.GetUserList(), Roles = pw.GetRoles() };

            return(CS.ReturnForJQuery(new JavaScriptSerializer().Serialize(JsonRet)));
        }
コード例 #7
0
        public List <GetUserProfileObject> GetUserList(string SingleSignOnConf)
        {
            List <GetUserProfileObject> utentiSSON = GetSingleSignONUsers(SingleSignOnConf);

            try
            {
                string sqlquery = string.Format("Select * from UserRoles");
                Sqlconn.Open();
                try
                {
                    DataTable dtres = new DataTable();
                    using (SqlCommand comm = new SqlCommand(sqlquery, Sqlconn))
                    {
                        using (SqlDataAdapter da = new SqlDataAdapter(comm))
                        {
                            da.Fill(dtres);
                        }
                    }

                    foreach (DataRow userrow in dtres.Rows)
                    {
                        GetUserProfileObject user = utentiSSON.Find(u => u.UserCode == userrow["UserCode"].ToString());
                        if (user == null)
                        {
                            DeleteUserforSynk(userrow["UserCode"].ToString());
                            continue;
                        }
                        UserRolesEnum ruolo = UserRolesEnum.User;
                        if (user.IsSuperAdmin)
                        {
                            ruolo = UserRolesEnum.Administrator;
                        }
                        else
                        {
                            ruolo = (UserRolesEnum)Convert.ToInt32(userrow["RoleId"].ToString());
                        }

                        user.UserRole = new UserRoleObject()
                        {
                            RoleId = (int)ruolo, Role = ruolo.ToString()
                        };
                    }
                    utentiSSON.FindAll(u => u.UserRole == null).ForEach(u =>
                    {
                        UserRolesEnum ruolo = UserRolesEnum.User;
                        if (u.IsSuperAdmin)
                        {
                            ruolo = UserRolesEnum.Administrator;
                        }
                        u.UserRole = new UserRoleObject()
                        {
                            RoleId = (int)ruolo, Role = ruolo.ToString()
                        };
                    });

                    return(utentiSSON);
                }
                catch (Exception) { throw; }
                finally
                {
                    Sqlconn.Close();
                }
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
                throw new Exception(string.Format(ErrorOccuredMess, ex.Message));
            }
        }