Ejemplo n.º 1
0
        // PUT api/appuser/5
        public HttpResponseMessage Putappuser(string id, appuser appuser)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != appuser.userid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            db.Entry(appuser).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 2
0
        /// <summary> </summary>
        public void save_stub([ARDataBind("item", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] posting item,
                              String post_type,
                              Boolean skiplayout
                              )
        {
            if (skiplayout)
            {
                CancelLayout();
            }
            CancelView();

            item.site      = siteService.getCurrentSite();
            item.theme     = themeService.current_theme_alias();
            item.published = false;

            appuser user = userService.getUserFull();

            item.owner   = user;
            item.editors = new List <appuser>()
            {
                user
            };

            item.post_type = getPostType(post_type);
            item.alias     = item.name.Replace(' ', '-').ToLower();//should add a check here
            ActiveRecordMediator <posting> .Save(item);

            RenderText("true");
        }
Ejemplo n.º 3
0
        /// <summary> </summary>
        public static Boolean loginUser()
        {
            String username = System.Web.HttpContext.Current.Response.Cookies["unldap"].Value; //Authentication.authenticate();

            HttpContext.Current.Request.Cookies["unldap"].Value = username;                    //Maybe this should be md5'd?
            // save user in database
            appuser[] user_list = ActiveRecordBase <appuser> .FindAll();

            appuser temp = null;

            foreach (appuser user in user_list)
            {
                if (!string.IsNullOrEmpty(user.nid) && user.nid.ToUpper() == username.ToUpper())
                {
                    temp = user;
                }
            }
            if (temp != null)
            {
                temp.logedin = true;
                ActiveRecordMediator <appuser> .Save(temp);

                return(temp.logedin);
            }
            return(false);
        }
Ejemplo n.º 4
0
        /// <summary> </summary>
        public static appuser getUser()
        {
            // this needs to change back to the session
            appuser user = setUser();// HttpContext.Current.Session["you"] == null ? setUser() : (users)HttpContext.Current.Session["you"];

            return(user);
        }
Ejemplo n.º 5
0
        /// <summary> </summary>
        public void edit_user(int id, int page)
        {
            appuser user = ActiveRecordBase <appuser> .Find(id);

            if (!userService.checkPrivleage("edit_users") && user != userService.getUser())
            {
                Flash["error"] = "Sorry you are not able to edit this user.";
                RedirectToAction("list");
                return;
            }

            PropertyBag["history"] = PaginationHelper.CreatePagination((IList)ActiveRecordBase <logs> .FindAll(Order.Desc("date"),
                                                                                                               new List <AbstractCriterion>()
            {
                Expression.Eq("nid", user.nid)
            }.ToArray()
                                                                                                               ).ToList(), 15, page);
            //media_types imgtype = ActiveRecordBase<media_types>.Find(1); //TODO restore
            //PropertyBag["images"] = imgtype.media_typed; //Flash["images"] != null ? Flash["images"] :
            //PropertyBag["userimages"] = user.media; //TODO restore
            PropertyBag["user"]   = user;
            PropertyBag["groups"] = ActiveRecordBase <user_group> .FindAll();

            RenderView("edit");
        }
Ejemplo n.º 6
0
        /// <summary> </summary>
        public void delete_user(int id)
        {
            appuser auth = ActiveRecordBase <appuser> .Find(id);

            ActiveRecordMediator <appuser> .Delete(auth);

            RedirectToReferrer();
        }
Ejemplo n.º 7
0
        /// <summary> </summary>
        public void absorb_user(int absorber, int absorbed)
        {
            appuser absorbing_auth = ActiveRecordBase <appuser> .Find(absorber);

            appuser auth_absorbed = ActiveRecordBase <appuser> .Find(absorbed);

            //ActiveRecordMediator<appuser>.Delete(auth);
            RedirectToReferrer();
        }
Ejemplo n.º 8
0
        /// <summary> </summary>
        public void new_user()
        {
            appuser user = new appuser();

            PropertyBag["user"]   = user;
            PropertyBag["groups"] = ActiveRecordBase <user_group> .FindAll();

            RenderView("edit");
        }
Ejemplo n.º 9
0
        /// <summary> </summary>
        public static bool setSessionPrivleage(appuser user, string privilege)
        {
            bool flag = false;

            if (user != null)
            {
                flag = user.groups.privileges.Any(item => item.alias == privilege);
            }
            HttpContext.Current.Session[privilege] = flag;
            return(flag);
        }
Ejemplo n.º 10
0
        /// <summary> </summary>
        public static Boolean isActive(appuser user)
        {
            int  timeThreshold = -2; //TODO Set as site perference
            bool active        = false;

            if (user != null && (!user.active || user.last_active < DateTime.Today.AddHours(timeThreshold)))
            {
                active = true;
            }
            return(active);
        }
Ejemplo n.º 11
0
        // GET api/appuser/5
        public appuser Getappuser(string id)
        {
            appuser appuser = db.appuser.Find(id);

            if (appuser == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(appuser);
        }
Ejemplo n.º 12
0
        /// <summary> </summary>
        public static appuser setUser()
        {
            String  uname = getNid();
            appuser user  = null;

            if (!String.IsNullOrWhiteSpace(uname))
            {
                try {
                    user = ActiveRecordBase <appuser> .FindAllByProperty("nid", uname).FirstOrDefault();
                } catch { return(null); }
            }
            //HttpContext.Current.Session["you"] = user;
            return(user);
        }
Ejemplo n.º 13
0
        // POST api/appuser
        public HttpResponseMessage Postappuser(appuser appuser)
        {
            if (ModelState.IsValid)
            {
                db.appuser.Add(appuser);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, appuser);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = appuser.userid }));
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Ejemplo n.º 14
0
        /// <summary> </summary>
        public static appuser getUserFull()
        {
            appuser userbase = getUser();
            appuser user     = null;

            if (userbase != null)
            {
                int id = getUser().baseid;

                if (id > 0)
                {
                    user = ActiveRecordBase <appuser> .Find(id);
                }
            }
            return(user);
        }
Ejemplo n.º 15
0
        /// <summary> </summary>
        public void admin()
        {
            appuser user = userService.getUserFull();

            if (user != null)
            {
                IList <posting> events = user.getUserPostings(5);
                PropertyBag["events"] = events;

                IList <posting> temp = new List <posting>();

                posting[] erroredEvents = ActiveRecordBase <posting> .FindAll().Where(x => x.outputError != null).ToArray();

                PropertyBag["erroredEvents"] = erroredEvents;

                //PropertyBag["user"] = user;
                IList <appuser> activeUser = new List <appuser>();
                appuser[]       _users     = ActiveRecordBase <appuser> .FindAllByProperty("logedin", true);

                if (_users.ToList().Count > 0)
                {
                    foreach (appuser _user in _users)
                    {
                        if (_user != null && _user.last_active > DateTime.Today.AddHours(-1))
                        {
                            activeUser.Add(_user);
                        }
                    }
                    PropertyBag["activeUsers"] = activeUser;
                }

                /*ExchangeService _service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                 * _service.Credentials = new WebCredentials("jeremy.bass", "bA03s17s82!");
                 * _service.AutodiscoverUrl("*****@*****.**");*/
                IList <Appointment> tmp = new List <Appointment>();

                /*CalendarView calendarView = new CalendarView(DateTime.Now, DateTime.Now.AddDays(5));
                 * foreach (Appointment appointment in _service.FindAppointments(WellKnownFolderName.Calendar, calendarView)) {
                 *  tmp.Add(appointment);
                 * }*/
                PropertyBag["ExchangeService"] = tmp;
                PropertyBag["activeUsers"]     = activeUser;
                //PropertyBag["analytics"] = seoService.getGAAnalytics();
            }
            //switch to the theme based one so there is customized dashboard
            RenderView("../admin/splash");
        }
Ejemplo n.º 16
0
        /// <summary> </summary>
        public void share(int uid, int itemid)
        {
            dynamic item = ActiveRecordBase <_base> .Find(itemid);

            if (item.owner.baseid == userService.getUser().baseid)
            {
                appuser user = ActiveRecordBase <appuser> .Find(uid);

                Flash["message"] = "Shared a " + item.post_type.name + " item with " + user.display_name + ".";
                logger.writelog("Shared item with " + user.display_name, getView(), getAction(), item.baseid);
                item.users.Add(user);
                ActiveRecordMediator <publish_base> .Save(item);

                RenderText("True");
            }
            else
            {
                logger.writelog("Failed to share item", getView(), getAction(), item.baseid);
                RenderText("False");
            }
        }
Ejemplo n.º 17
0
        // DELETE api/appuser/5
        public HttpResponseMessage Deleteappuser(string id)
        {
            appuser appuser = db.appuser.Find(id);

            if (appuser == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.appuser.Remove(appuser);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, appuser));
        }
Ejemplo n.º 18
0
        /// <summary> </summary>
        public static void writelog(string txt, appuser user, string controller, string action, int obj_id)
        {
            if (Controllers.installController.is_installed())
            {
                logs loger = new logs();
                loger.entry = txt;
                loger.nid   = user == null?userService.getNid() : user.nid;

                loger.ip         = userService.getUserIp();
                loger.date       = DateTime.Now;
                loger.controller = controller;
                loger.action     = action;
                loger.obj_id     = obj_id;
                ActiveRecordMediator <logs> .Save(loger);
            }
            else
            {
                //DateTime time = DateTime.Now;
                //string format = "MMM ddd d HH:mm yyyy";
                //file_handler.write_to_file("logs/install.log", time.ToString(format)+" "+ txt, true);
            }
        }
Ejemplo n.º 19
0
        /// <summary> </summary>
        public void create(String post_type, Boolean skipLayout)
        {
            posting tmp = new posting();

            tmp.tmp = true;

            tmp.site      = siteService.getCurrentSite();
            tmp.theme     = themeService.current_theme_alias();
            tmp.published = false;

            appuser user = userService.getUserFull();

            tmp.owner   = user;
            tmp.editors = new List <appuser>()
            {
                user
            };
            tmp.editing   = user;
            tmp.post_type = getPostType(post_type);
            ActiveRecordMediator <posting> .Save(tmp);

            RedirectToUrl("~/post/edit_post.castle?id=" + tmp.baseid + (skipLayout ? "&skipLayout=true" : ""));
        }
        /// <summary> </summary>
        public void AuthorizeRequestToken(string requestToken, appuser user)
        {
            if (requestToken == null)
            {
                throw new ArgumentNullException("requestToken");
            }
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            var tokenRow = GlobalApplication.AuthTokens.SingleOrDefault(
                tokenCandidate => tokenCandidate.Token == requestToken &&
                tokenCandidate.State == TokenAuthorizationState.UnauthorizedRequestToken);

            if (tokenRow == null)
            {
                throw new ArgumentException();
            }

            tokenRow.State = TokenAuthorizationState.AuthorizedRequestToken;
            tokenRow.User  = user;
        }
Ejemplo n.º 21
0
        /// <summary> </summary>
        public static Boolean logoutUser()
        {
            String username = HttpContext.Current.Request.Cookies["unldap"] != null ? HttpContext.Current.Request.Cookies["unldap"].Value : null;

            if (username != null)
            {
                // save user in database
                appuser[] user_list = ActiveRecordBase <appuser> .FindAll();

                appuser temp = null;
                foreach (appuser user in user_list)
                {
                    if (!string.IsNullOrEmpty(user.nid) && user.nid.ToUpper() == username.ToUpper())
                    {
                        temp = user;
                    }
                }
                temp.logedin = false;
                ActiveRecordMediator <appuser> .Save(temp);

                return(temp.logedin ? false : true);
            }
            return(true);
        }
Ejemplo n.º 22
0
 /// <summary> </summary>
 public Boolean hasGroup(String group, appuser user)
 {
     return(group == user.groups.name);
 }
Ejemplo n.º 23
0
        /// <summary> </summary>
        public void update_user(
            [ARDataBind("user", Validate = true, AutoLoad = AutoLoadBehavior.NewInstanceIfInvalidKey)] appuser user,
            [ARDataBind("image", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] posting image,
            HttpPostedFile newimage,
            int[] Sections,
            string apply,
            string cancel,
            Boolean ajaxed,
            String[] value,
            String[] meta_key
            )
        {
            if (user.user_meta_data != null)
            {
                user.user_meta_data.Clear();
            }
            else
            {
                user.user_meta_data = new List <user_meta_data>();
            }
            int i = 0;

            foreach (String item in value)
            {
                user_meta_data tmp = new user_meta_data()
                {
                    value    = item,
                    meta_key = meta_key[i]
                };
                i++;
                user.user_meta_data.Add(tmp);
            }

            if (cancel != null)
            {
                RedirectToAction("list_user");
                return;
            }
            if (user.groups == null || user.groups.baseid == 0)
            {
                List <AbstractCriterion> baseEx = new List <AbstractCriterion>();
                baseEx.Add(Expression.Eq("default_group", true));
                baseEx.Add(Expression.Eq("isAdmin", true));
                user.groups = ActiveRecordBase <user_group> .FindFirst(baseEx.ToArray());
            }

            try {
                ActiveRecordMediator <appuser> .Save(user);

                if (user == userService.getUser())
                {
                    userService.setUser();
                }
            } catch (Exception ex) {
                Flash["error"] = ex.Message;
                Flash["user"]  = user;
            }
            if (apply != null || ajaxed)
            {
                logger.writelog("Applied user edits", getView(), getAction(), user.baseid);
                if (user.baseid > 0)
                {
                    if (ajaxed)
                    {
                        CancelLayout();
                        RenderText(user.baseid.ToString());
                    }
                    else
                    {
                        RedirectToUrl("~/users/edit_user.castle?id=" + user.baseid);
                    }
                    return;
                }
                else
                {
                    RedirectToReferrer();
                    return;
                }
            }
            else
            {
                logger.writelog("Saved user edits on", getView(), getAction(), user.baseid);
                RedirectToAction("list_users");
                return;
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// This take a file, regardless of if there is a post already for this file,
        /// and ingests it to the database as a posting.
        /// </summary>
        /// <param name="file">What file to use</param>
        /// <param name="name">Basic post data.</param>
        /// <param name="theme">What theme should it respond to?</param>
        /// <param name="posting_type">What posting type should be used</param>
        /// <param name="mode"></param>
        /// <param name="version">The starting version</param>
        /// <param name="revision">The starting revision</param>
        /// <param name="user">the user the post belongs to</param>
        /// <param name="loads_file">Should the post use the file or the database.</param>
        /// <returns></returns>
        /// <remarks>A new pst from file may only be created from a file with in the working folder or it'll fail to make the post.</remarks>
        public static posting create_post_from_file(String file, String name, String theme, String posting_type, String mode, int version, int revision, appuser user, Boolean loads_file)
        {
            posting doc_tmp = new posting();
            site    site    = siteService.getCurrentSite();

            file = file_handler.normalize_path(file);

            String[] fpath       = file.Split(new string[] { posting_type + "/" }, StringSplitOptions.None);
            String   static_file = fpath[fpath.Length - 1].Trim('/');

            String dst = "";

            String basepath = themeService.theme_path(site, theme, mode, posting_type);

            dst = basepath.Trim('/') + "/" + static_file.Trim('/');

            if (!file_info.file_exists(dst))
            {
                basepath = themeService.theme_path(site, "base", mode, posting_type);
                dst      = basepath.Trim('/') + "/" + static_file.Trim('/');
            }

            /*if (!file_info.is_relative_path(file)) { //if it's not absoulte then lets try to figure out what was wanted
             * } else {
             *  //the path was absolute so lets trust it's what was meant to be
             *  dst = file;
             * }*/
            if (file_info.file_exists(dst))
            {
                posting_type ptype = ActiveRecordBase <posting_type> .FindFirst(new List <AbstractCriterion>() { Expression.Eq("alias", posting_type) }.ToArray());

                Hashtable fileinfo = get_post_file_info(dst);
                // if there was any file metadata that belongs to this app, apply it to the post
                doc_tmp = new posting()
                {
                    loads_file  = loads_file,
                    static_file = static_file,
                    content     = file_handler.read_from_file(dst),
                    post_type   = ptype,
                    useTiny     = ptype.useTiny,
                    is_Code     = ptype.is_Code,
                    owner       = user,
                    editors     = new List <appuser>()
                    {
                        user
                    }
                };

                // loop over the object properties and see if they are in the file meta info
                // if they are apply them.
                List <string> properties = objectService.get_type_properties("posting");
                foreach (String property in fileinfo.Keys)
                {
                    if (properties.Contains(property))
                    {
                        PropertyInfo propInfo = doc_tmp.GetType().GetProperty(property);
                        if (propInfo != null)
                        {
                            String prop_type = propInfo.PropertyType.Namespace;
                            if (prop_type == "System")
                            {
                                String value = fileinfo[property].ToString();
                                if (value != null && value != "")
                                {
                                    dynamic val = Convert.ChangeType(value, propInfo.PropertyType, CultureInfo.InvariantCulture);
                                    propInfo.SetValue(doc_tmp, val, null);
                                }
                            }
                        }
                    }
                }
                ActiveRecordMediator <posting> .SaveAndFlush(doc_tmp);

                //backup minimums for a respectably factioning out object
                if (String.IsNullOrWhiteSpace(doc_tmp.name))
                {
                    doc_tmp.name = name;
                }
                if (String.IsNullOrWhiteSpace(doc_tmp.alias))
                {
                    doc_tmp.alias = doc_tmp.name.Replace(' ', '-').ToLower();
                }
                if (doc_tmp.version > 0)
                {
                    doc_tmp.version = version;
                }
                if (doc_tmp.revision > 0)
                {
                    doc_tmp.revision = revision;
                }
                if (String.IsNullOrWhiteSpace(doc_tmp.theme))
                {
                    doc_tmp.theme = theme;
                }
                if (fileinfo["is_core"] == null)
                {
                    doc_tmp.is_core = ptype.is_core;
                }
                if (fileinfo["is_admin"] == null)
                {
                    doc_tmp.is_admin = ptype.is_admin;
                }
                if (fileinfo["is_frontend_editable"] == null)
                {
                    doc_tmp.is_frontend_editable = true;
                }
                if (fileinfo["is_visible"] == null)
                {
                    doc_tmp.is_visible = true;
                }
                if (fileinfo["is_default"] == null)
                {
                    doc_tmp.is_default = true;
                }


                ActiveRecordMediator <posting> .Save(doc_tmp);

                doc_tmp = versionService.make_working_post(doc_tmp, static_file);
            }
            return(doc_tmp);
        }
Ejemplo n.º 25
0
        /// <summary> </summary>
        public bool Perform(ExecuteWhen exec, IEngineContext context, IController controller, IControllerContext controllerContext)
        {
            //this should be removed
            if (!Controllers.BaseController.authenticated())
            {
                System.Web.HttpContext.Current.Response.Redirect("~/center/login.castle");
            }

            controllerContext.PropertyBag["post_types"] = ActiveRecordBase <posting_type> .FindAll();

            controllerContext.PropertyBag["userService"]   = userService;
            controllerContext.PropertyBag["helperService"] = helperService;
            controllerContext.PropertyBag["user"]          = userService.getUserFull();

            //return true;

            if (context.Request.IsLocal)
            {
                if (!controllerContext.Action.Contains("install") && ActiveRecordBase <appuser> .Exists())
                {
                    //controllerContext.PropertyBag["campuses"] = ActiveRecordBase<campus>.FindAll();
                    controllerContext.PropertyBag["post_types"] = ActiveRecordBase <posting_type> .FindAll();

                    controllerContext.PropertyBag["userService"]   = userService;
                    controllerContext.PropertyBag["helperService"] = helperService;
                    controllerContext.PropertyBag["user"]          = userService.getUserFull();
                }
                return(true);
            }
            // Read previous authenticated principal from session
            // (could be from cookie although with more work)
            User user = (User)context.Session["user"];

            // Redirect to dailystellar.wsu.edu because dailystellar.com can't catch the cookie
            //if (context.Request.Uri.ToString().ToLower().Contains("dailystellar.com"))
            //{
            //     context.Response.Redirect("http://dev.stellar.wsu.edu/admin");
            //     return false;
            //}
            // Sets the principal as the current user
            context.CurrentUser = user;
            if (Controllers.BaseController.authenticated())
            {
                return(true);
            }
            // Checks if it is OK
            //if (context.CurrentUser == null ||
            //    !context.CurrentUser.Identity.IsAuthenticated ||
            //    !Authentication.logged_in())
            if (Controllers.BaseController.authenticated())
            {
                // Not authenticated, redirect to login
                String username = userService.getNid();



                appuser[] users = ActiveRecordBase <appuser> .FindAllByProperty("nid", username);

                if (users.Length == 0)
                {
                    //context.Response.RedirectToUrl("~/admin", false);
                    //return false;
                }
                //context.Session["manager"] = true;
                //context.Cookies["unldap"].Value = username;
                user = new User(username, new String[0]);
                context.CurrentUser = user;
                System.Threading.Thread.CurrentPrincipal = user;
            }


            if (userService.isLogedIn())// || Authentication.logged_in()) /* not 100% we can't just strip off the Authentication.*/
            {
                appuser currentUser = userService.getUser();
                if (currentUser != null)
                {
                    appuser you = ActiveRecordBase <appuser> .Find(currentUser.baseid);

                    you.logedin     = true;
                    you.last_active = DateTime.Now;
                    ActiveRecordMediator <appuser> .Update(you);

                    ActiveRecordMediator <appuser> .Save(you);
                }
            }
            if (!controllerContext.Action.Contains("install"))
            {
                // controllerContext.PropertyBag["campuses"] = ActiveRecordBase<campus>.FindAll();
                controllerContext.PropertyBag["post_types"] = ActiveRecordBase <posting_type> .FindAll();

                controllerContext.PropertyBag["userService"]   = userService;
                controllerContext.PropertyBag["helperService"] = helperService;
                controllerContext.PropertyBag["user"]          = userService.getUserFull();
            }
            // Everything is ok
            return(true);
        }
Ejemplo n.º 26
0
        /// <summary> </summary>
        public static appuser getUserFull(int id)
        {
            appuser user = ActiveRecordBase <appuser> .Find(id);

            return(user);
        }
Ejemplo n.º 27
0
 /// <summary> </summary>
 public static void writelog(string txt, appuser user)
 {
     writelog(txt, user, "", "", 0);
 }
Ejemplo n.º 28
0
        /// <summary> </summary>
        public static contact_profile get_defaultContactProfile(appuser user)
        {
            contact_profile profile = user.contact_profiles.FirstOrDefault(x => x.isDefault == true);

            return(profile);
        }
Ejemplo n.º 29
0
        /// <summary> </summary>
        public static bool checkPrivleage(appuser user, string privilege)
        {
            bool flag = setSessionPrivleage(user, privilege);// (HttpContext.Current.Session[privilege] == null || String.IsNullOrWhiteSpace(HttpContext.Current.Session[privilege].ToString())) ? setSessionPrivleage(user, privilege) : (bool)HttpContext.Current.Session[privilege];

            return(flag);
        }
Ejemplo n.º 30
0
 /// <summary> </summary>
 public static void writelog(string txt, appuser user, int obj_id)
 {
     writelog(txt, user, "", "", obj_id);
 }