Example #1
0
        /// <summary>
        /// Try to login into the remote erver with the given credentials
        /// </summary>
        /// <param name="user"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns>true if the login has been successful; false otherwise</returns>
        public static ErrorCodes TryLogin(UserClient user, string username, string password, IPluginManager pluginManager)
        {
            // Test login
            UserWS repoUser = new UserWS();

            Snip2Code.Model.Entities.User loggedUser = repoUser.LoginUser(username, password);

            if ((loggedUser != null) && (loggedUser.ID > 0))
            {
                // Save credentials
                BaseWS.Username   = username;
                BaseWS.Password   = password;
                BaseWS.IdentToken = string.Empty;
                user.SaveUserPreferences();

                // change the logged user on the package
                LoginPoller poller = new LoginPoller(username, password, string.Empty, false, pluginManager);
                if (ClientUtils.LoginTimer != null)
                {
                    ClientUtils.LoginTimer.Dispose();
                }
                ClientUtils.LoginTimer = new System.Threading.Timer(poller.RecallLogin, null, 0, AppConfig.Current.LoginRefreshTimeSec * 1000);
                return(ErrorCodes.OK);
            }

            if (repoUser.LastErrorCode == ErrorCodes.OK)
            {
                return(ErrorCodes.NOT_LOGGED_IN);
            }
            else
            {
                return(repoUser.LastErrorCode);
            }
        }
Example #2
0
        public static ErrorCodes TryLoginOneAll(UserClient user, IPluginManager pluginManager)
        {
            UserWS repoUser   = new UserWS();
            string identToken = BaseWS.IdentToken;

            Snip2Code.Model.Entities.User loggedUser = repoUser.LoginUserOneAll(identToken);

            if ((loggedUser != null) && (loggedUser.ID > 0))
            {
                // Save credentials
                BaseWS.Username = string.Empty;
                BaseWS.Password = string.Empty;
                user.SaveUserPreferences();

                // change the logged user on the package
                LoginPoller poller = new LoginPoller(string.Empty, string.Empty, identToken, true, pluginManager);
                if (ClientUtils.LoginTimer != null)
                {
                    ClientUtils.LoginTimer.Dispose();
                }
                ClientUtils.LoginTimer = new System.Threading.Timer(poller.RecallLogin, null, 0, AppConfig.Current.LoginRefreshTimeSec * 1000);

                return(ErrorCodes.OK);
            }
            else
            {
                // something went wrong on the login: reload the oneAllPage
                BaseWS.IdentToken = string.Empty;

                if (repoUser.LastErrorCode == ErrorCodes.OK)
                {
                    return(ErrorCodes.NOT_LOGGED_IN);
                }
                else
                {
                    return(repoUser.LastErrorCode);
                }
            }
        }
Example #3
0
        /// <summary>
        /// This is the init/copy method for this class.
        /// It should be used by the children classes in the constructor in order to correctly fill the properties of the object.
        /// </summary>
        /// <param name="objToCopy"></param>
        protected bool Init(User objToCopy)
        {
            if (objToCopy == null)
                return false;

            //save the values of the properties with private setters:
            ID = objToCopy.ID;
            EMail = objToCopy.EMail;
            Name = objToCopy.Name;
            LastName = objToCopy.LastName;
            NickName = objToCopy.NickName;
            Active = objToCopy.Active;
            AcctCreated = objToCopy.AcctCreated;
            LoginFirst = objToCopy.LoginFirst;
            LoginLast = objToCopy.LoginLast;
            Preferences = objToCopy.Preferences;
            PictureID = objToCopy.PictureID;
            HasValidMail = objToCopy.HasValidMail;
            Points = objToCopy.Points;
            Role = objToCopy.Role;
            PersonalGroupID = objToCopy.PersonalGroupID;
            DefaultGroupID = objToCopy.DefaultGroupID;

            //if the object to copy comes from a JSON deserialization, tke the arguments from the helper class:
            if (objToCopy is UserComm)
            {
                UserComm jsonObj = (UserComm)objToCopy;
                ID = (objToCopy.ID > 0) ? objToCopy.ID : jsonObj.CommID;
                EMail = (!string.IsNullOrEmpty(objToCopy.EMail)) ? objToCopy.EMail : jsonObj.CommEMail;
                NickName = (!string.IsNullOrEmpty(objToCopy.NickName)) ? objToCopy.NickName : jsonObj.CommNickName;
                Preferences = (objToCopy.Preferences == null) ? objToCopy.Preferences : jsonObj.CommPreferences;
                //PictureID = (objToCopy.PictureID > 0) ? objToCopy.PictureID : jsonObj.CommPictureID;
                Role = (objToCopy.Role > 0) ? objToCopy.Role : jsonObj.CommRole;
                PersonalGroupID = (objToCopy.PersonalGroupID > 0) ? objToCopy.PersonalGroupID : jsonObj.CommPersonalGroupID;
            }

            return true;
        }
Example #4
0
        /// <summary>
        /// Tells whether the given user is allowed to modify the content of the current snippet and/or to delete it
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool IsAllowedToEdit(User user)
        {
            if (user == null)
                return false;

            //the user should be an admin of the group that owns the snippet:
            if (user.AdministerGroup(OwnerGroupID))
                return true;
            
            //or can be a simple user, if he is the creator of the snippet:
            return ((user.ID == CreatorID) && user.BelongsToGroup(OwnerGroupID));         
        }
Example #5
0
        /// <summary>
        /// Tells whether the given user is allowed to change visibility of the current snippet
        /// </summary>
        /// <param name="user"></param>
        /// <param name="toChangeGroupOrUnshare">true if this method is used to check if the user is able to change the group or unshare the snippet</param>
        /// <returns></returns>
        public bool IsAllowedToChangeVisibility(User user, bool toChangeGroupOrUnshare = false)
        {
            if (user == null)
                return false;

            if (toChangeGroupOrUnshare)
                return (CreatorID == user.ID) && user.BelongsToGroup(OwnerGroupID); //the user should be the creator and belong to the owner group
            else
                return user.AdministerGroup(OwnerGroupID); //the user should be an admin of the group that owns the snippet
        }
Example #6
0
        /// <summary>
        /// Tells whether the given user is allowed to view the content of the current snippet
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool IsAllowedToView(User user)
        {
            if (Visibility >= ShareOption.Public)
                return true;
            if (user == null)
                return false;

            return user.BelongsToGroup(OwnerGroupID);
        }
Example #7
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        #region Cache Methods
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        public void UpdateCache(User user)
        {
            //anything to do here until we implement the cache on client side...
        }
Example #8
0
 public bool ChangeUserProfile(User modified)
 {
     throw new NotImplementedException();
 }