Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Andrew Wiggins 3 posts 93 karma points
    Feb 20, 2018 @ 09:39
    Andrew Wiggins
    0

    Programmatically saving member password.

    I have used the login and register snippets and wish to provide a retrieve password service using a form. but receive the error 'CS1502: The best overloaded method match for 'Umbraco.Core.Services.IMemberService.SavePassword(Umbraco.Core.Models.IMember, string)' has some invalid arguments' for the code below.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage @using System.Web.Mvc.Html @using ClientDependency.Core.Mvc @using System.Net.Mail @using System.Text.RegularExpressions; @using System.Web.Security; @using Umbraco.Core; @using Umbraco.Core.Models; @using Umbraco.Core.Services; @using Umbraco.Web.WebApi; @using Umbraco.Web; @using Umbraco.Web.Models; @using Umbraco.Web.Controllers;

    @{ var Message=""; if(IsPost) {

        var email = Request["tb_email"];
        var cMember = ApplicationContext.Services.UserService.GetByEmail(email);
    
        var member = Members.GetByEmail(email);
        var memberid = member.Id;
        var memberName = Membership.GetUser(member.Id).UserName;
    
       if(member != null)
        {
            @* GENERATE NEW PASSWORD *@
            var  newpassword =  Membership.GeneratePassword(10, 1).ToString();
            newpassword = Regex.Replace(newpassword, @"[^a-zA-Z0-9]", m => "9");
    
            @* Change the password to the new generated one above *@
    
            ApplicationContext.Current.Services.MemberService.SavePassword(memberid, newpassword); 
    
            Message ="<h3 style='color:red;'>Your new password has been sent to "  + email + "</h3>";
    
            }
                else
            {
                Message ="<h3 style='color:red;'>Sorry no account exists for " + email + "</h3>";
        }
    }
    else
    {
            Message="This is without postback";
    }
    

    }

    @Umbraco.Field("pageName")

    @Html.Raw(Message)

    Please enter your email address, and we will generate a new password for you and send it straight to your inbox.


  • Steve Morgan 1278 posts 4216 karma points c-trib
    Feb 20, 2018 @ 10:50
    Steve Morgan
    0

    Hi Andrew,

    Try this - you need to pass the member, not the id.

    ApplicationContext.Current.Services.MemberService.SavePassword(member, newpassword);

  • Andrew Wiggins 3 posts 93 karma points
    Feb 20, 2018 @ 10:57
    Andrew Wiggins
    0

    Thanks but still get !

    Compiler Error Message: CS1502: The best overloaded method match for 'Umbraco.Core.Services.IMemberService.SavePassword(Umbraco.Core.Models.IMember, string)' has some invalid arguments
    

    Source Error:

    Line 35: @* Change the password to the new generated one above*@ Line 36:
    Line 37: ApplicationContext.Current.Services.MemberService.SavePassword(member, newpassword);

  • Steve Morgan 1278 posts 4216 karma points c-trib
    Feb 20, 2018 @ 11:41
    Steve Morgan
    0

    Hi,

    Sorry - I missed the problem first time around.

    It's here:

    var member = Members.GetByEmail(email);

    Change this to :

    var member = ApplicationContext.Current.Services.MemberService.GetByEmail(email);

  • Andrew Wiggins 3 posts 93 karma points
    Feb 20, 2018 @ 12:02
    Andrew Wiggins
    100

    Perfect!

    Many thanks for your time.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies