示例#1
0
        // GET: api/InvestorPerson/5
        //[ResponseType(typeof(z_Person))]
        public async Task <JsonResult <z_Person> > GetPerson(int id)
        {
            IUser currentUser = null;

            var userTicket = new System.Web.HttpContextWrapper(System.Web.HttpContext.Current).GetUmbracoAuthTicket();

            if (userTicket != null)
            {
                currentUser = ApplicationContext.Services.UserService.GetByUsername(userTicket.Name);
            }


            if (currentUser == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }


            z_Person person = await db.z_Person.FindAsync(id);

            if (person == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            return(Json(person));
        }
示例#2
0
        public int CreateContentNode(string nodeName, string nodeTypeAlias, int parentNode, Dictionary <string, string> properties, List <string> roles = null)
        {
            try
            {
                //parentid = 1189
                Int32          uid = 0;
                ContentService cs  = (ContentService)ApplicationContext.Current.Services.ContentService;

                UserService us = (UserService)ApplicationContext.Current.Services.UserService;

                Umbraco.Core.Models.Membership.IUser usr = us.GetByUsername("*****@*****.**");

                if (usr != null)
                {
                    uid = usr.Id;
                }


                // Create the Node under
                Content parent = (Content)cs.GetById(parentNode);

                IContent c = (IContent)cs.CreateContent(nodeName, parent, nodeTypeAlias);

                foreach (string property in properties.Keys)
                {
                    c.SetValue(property, properties[property].ToString());
                }

                cs.SaveAndPublishWithStatus(c, uid);

                return(c.Id);
            }
            catch (Exception ex) { return(0); }
        }
示例#3
0
        /// <summary>
        /// Create and publish the document programatically
        /// </summary>
        /// <param name="nodeName"></param>
        /// <param name="properties"></param>
        /// <param name="documentType"></param>
        /// <param name="parentId"></param>
        /// <returns>node id</returns>
        public int CreateDetailContentNode(string nodeName, Dictionary <string, string> properties, List <string> roles = null)
        {
            try
            {
                //parentid = 1189
                Int32          uid = 0;
                ContentService cs  = (ContentService)ApplicationContext.Current.Services.ContentService;

                UserService us = (UserService)ApplicationContext.Current.Services.UserService;

                Umbraco.Core.Models.Membership.IUser usr = us.GetByUsername("*****@*****.**");

                if (usr != null)
                {
                    uid = usr.Id;
                }


                // Create the Node under
                Content parent = (Content)cs.GetById(1189);

                Content c = (Content)cs.CreateContent(nodeName, parent, "propertyDetail");

                // Add values to the generic properties of the document
                if (properties != null)
                {
                    foreach (string property in properties.Keys)
                    {
                        //c.getProperty(properties[property]).Value = properties[property];
                        //c.Properties.
                    }
                }
                // Set the publish status of the document and there by create a new version

                /*if (roles != null)
                 * {
                 *  int loginDocId = Constants.NODE_ID_HOME;
                 *  int errorDocId = Constants.NODE_ID_HOME;
                 *  umbraco.cms.businesslogic.web.Access.ProtectPage(false, d.Id, loginDocId, errorDocId);
                 *  foreach (string role in roles)
                 *  {
                 *      umbraco.cms.businesslogic.web.Access.AddMembershipRoleToDocument(d.Id, role);
                 *  }
                 * }*/
                // d.Publish(u);
                // Tell the runtime environment to publish this document
                cs.Publish(c, uid);
                return(c.Id);
            }
            catch (Exception ex) { return(0); }
        }
        /// <summary>
        /// This is used when the user is auth'd successfully and we need to return an OK with user details along with setting the current Principal in the request
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        private HttpResponseMessage SetPrincipalAndReturnUserDetail(IUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            var userDetail = Mapper.Map <UserDetail>(user);

            //update the userDetail and set their remaining seconds
            userDetail.SecondsUntilTimeout = TimeSpan.FromMinutes(GlobalSettings.TimeOutInMinutes).TotalSeconds;

            //create a response with the userDetail object
            var response = Request.CreateResponse(HttpStatusCode.OK, userDetail);

            //ensure the user is set for the current request
            Request.SetPrincipalForRequest(user);

            return(response);
        }
示例#5
0
        /// <summary>
        /// Changes the password for a user based on the many different rules and config options
        /// </summary>
        /// <param name="currentUser">The user performing the password save action</param>
        /// <param name="savingUser">The user who's password is being changed</param>
        /// <param name="passwordModel"></param>
        /// <param name="userMgr"></param>
        /// <returns></returns>
        public async Task <Attempt <PasswordChangedModel> > ChangePasswordWithIdentityAsync(
            IUser currentUser,
            IUser savingUser,
            ChangingPasswordModel passwordModel,
            BackOfficeUserManager <BackOfficeIdentityUser> userMgr)
        {
            if (passwordModel == null)
            {
                throw new ArgumentNullException("passwordModel");
            }
            if (userMgr == null)
            {
                throw new ArgumentNullException("userMgr");
            }

            //check if this identity implementation is powered by an underlying membership provider (it will be in most cases)
            var membershipPasswordHasher = userMgr.PasswordHasher as IMembershipProviderPasswordHasher;

            //check if this identity implementation is powered by an IUserAwarePasswordHasher (it will be by default in 7.7+ but not for upgrades)
            var userAwarePasswordHasher = userMgr.PasswordHasher as IUserAwarePasswordHasher <BackOfficeIdentityUser, int>;

            if (membershipPasswordHasher != null && userAwarePasswordHasher == null)
            {
                //if this isn't using an IUserAwarePasswordHasher, then fallback to the old way
                if (membershipPasswordHasher.MembershipProvider.RequiresQuestionAndAnswer)
                {
                    throw new NotSupportedException("Currently the user editor does not support providers that have RequiresQuestionAndAnswer specified");
                }
                return(ChangePasswordWithMembershipProvider(savingUser.Username, passwordModel, membershipPasswordHasher.MembershipProvider));
            }

            //if we are here, then a IUserAwarePasswordHasher is available, however we cannot proceed in that case if for some odd reason
            //the user has configured the membership provider to not be hashed. This will actually never occur because the BackOfficeUserManager
            //will throw if it's not hashed, but we should make sure to check anyways (i.e. in case we want to unit test!)
            if (membershipPasswordHasher != null && membershipPasswordHasher.MembershipProvider.PasswordFormat != MembershipPasswordFormat.Hashed)
            {
                throw new InvalidOperationException("The membership provider cannot have a password format of " + membershipPasswordHasher.MembershipProvider.PasswordFormat + " and be configured with secured hashed passwords");
            }

            //Are we resetting the password?? In ASP.NET Identity APIs, this flag indicates that an admin user is changing another user's password
            //without knowing the original password.
            if (passwordModel.Reset.HasValue && passwordModel.Reset.Value)
            {
                //if it's the current user, the current user cannot reset their own password
                if (currentUser.Username == savingUser.Username)
                {
                    return(Attempt.Fail(new PasswordChangedModel {
                        ChangeError = new ValidationResult("Password reset is not allowed", new[] { "resetPassword" })
                    }));
                }

                //if the current user has access to reset/manually change the password
                if (currentUser.HasSectionAccess(Umbraco.Core.Constants.Applications.Users) == false)
                {
                    return(Attempt.Fail(new PasswordChangedModel {
                        ChangeError = new ValidationResult("The current user is not authorized", new[] { "resetPassword" })
                    }));
                }

                //ok, we should be able to reset it
                var resetToken = await userMgr.GeneratePasswordResetTokenAsync(savingUser.Id);

                var newPass = passwordModel.NewPassword.IsNullOrWhiteSpace()
                    ? userMgr.GeneratePassword()
                    : passwordModel.NewPassword;

                var resetResult = await userMgr.ChangePasswordWithResetAsync(savingUser.Id, resetToken, newPass);

                if (resetResult.Succeeded == false)
                {
                    var errors = string.Join(". ", resetResult.Errors);
                    _logger.Warn <PasswordChanger>(string.Format("Could not reset user password {0}", errors));
                    return(Attempt.Fail(new PasswordChangedModel {
                        ChangeError = new ValidationResult("Could not reset password, errors: " + errors, new[] { "resetPassword" })
                    }));
                }

                return(Attempt.Succeed(new PasswordChangedModel()));
            }

            //we're not resetting it so we need to try to change it.

            if (passwordModel.NewPassword.IsNullOrWhiteSpace())
            {
                return(Attempt.Fail(new PasswordChangedModel {
                    ChangeError = new ValidationResult("Cannot set an empty password", new[] { "value" })
                }));
            }

            //we cannot arbitrarily change the password without knowing the old one and no old password was supplied - need to return an error
            //TODO: What if the current user is admin? We should allow manually changing then?
            if (passwordModel.OldPassword.IsNullOrWhiteSpace())
            {
                //if password retrieval is not enabled but there is no old password we cannot continue
                return(Attempt.Fail(new PasswordChangedModel {
                    ChangeError = new ValidationResult("Password cannot be changed without the old password", new[] { "oldPassword" })
                }));
            }

            if (passwordModel.OldPassword.IsNullOrWhiteSpace() == false)
            {
                //if an old password is suplied try to change it
                var changeResult = await userMgr.ChangePasswordAsync(savingUser.Id, passwordModel.OldPassword, passwordModel.NewPassword);

                if (changeResult.Succeeded == false)
                {
                    var errors = string.Join(". ", changeResult.Errors);
                    _logger.Warn <PasswordChanger>(string.Format("Could not change user password {0}", errors));
                    return(Attempt.Fail(new PasswordChangedModel {
                        ChangeError = new ValidationResult("Could not change password, errors: " + errors, new[] { "oldPassword" })
                    }));
                }
                return(Attempt.Succeed(new PasswordChangedModel()));
            }

            //We shouldn't really get here
            return(Attempt.Fail(new PasswordChangedModel {
                ChangeError = new ValidationResult("Could not change password, invalid information supplied", new[] { "value" })
            }));
        }
示例#6
0
        // GET: api/InvestorPerson
        public JsonResult <List <GetNbrOfQVM> > GetPersons()   // JsonResult<DbSet<z_Person>>
        {
            IUser currentUser = null;

            var userTicket = new System.Web.HttpContextWrapper(System.Web.HttpContext.Current).GetUmbracoAuthTicket();

            if (userTicket != null)
            {
                currentUser = ApplicationContext.Services.UserService.GetByUsername(userTicket.Name);

                var j = Request.RequestUri;
                var k = System.Web.HttpContext.Current.Request.UrlReferrer;

                if (currentUser == null || !InvestorDashboardPermission(currentUser.Id))
                {
                    var j1 = Request.RequestUri;
                    var k1 = System.Web.HttpContext.Current.Request.UrlReferrer;
                    if (k1 == null)
                    {
                        throw new HttpResponseException(HttpStatusCode.NotFound);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    // var j = Request.RequestUri;
                    //var k = System.Web.HttpContext.Current.Request.UrlReferrer;
                    //var h = new JsonSerializerSettings();

                    // HttpContext.Current.Response.ContentType = "application/json";

                    var k1 = System.Web.HttpContext.Current.Request.UrlReferrer;
                    if (k1 == null)
                    {
                        throw new HttpResponseException(HttpStatusCode.NotFound);
                    }

                    var res = new List <GetNbrOfQVM>();

                    foreach (var p in db.z_Person)
                    {
                        GetNbrOfQVM gbnr = new GetNbrOfQVM();
                        gbnr.Id        = p.PersonID;
                        gbnr.FirstName = p.FirstName;
                        gbnr.LastName  = p.LastName;
                        gbnr.Email     = p.Email;

                        gbnr.NbrOf = GetNbrOfInvest(gbnr.Id);

                        res.Add(gbnr);
                    }

                    return(Json(res)); //Json(db.z_Person);
                }
            }
            else
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
        }