在 Umbraco 7 上以编程方式登录成员(member)

标签 login umbraco umbraco7

我正在与这个作斗争。在 Umbraco 6 中,您可以使用以下方法轻松完成此操作:

Member.AddMemberToCache(
    Member.GetMemberFromEmail(email),
    true,
    new TimeSpan(0, 30, 0)
);

我在 umbraco 7 成员(member)的服务中找不到相同的东西。

最佳答案

在 Umbraco 7 中,您可以使用 Umbraco.Web.Security.MembershipHelper 类(class)。
它的一个实例可以通过 访问。成员(member) View 中的属性继承自:

  • Umbraco.Web.Mvc.UmbracoTemplatePage
  • Umbraco.Web.Mvc.UmbracoViewPage
  • Umbraco.Web.Mvc.UmbracoViewPage<T>

  • 也在 Controller 中继承自:
  • Umbraco.Web.WebApi.UmbracoApiController
  • Umbraco.Web.Mvc.SurfaceController

  • 以编程方式登录成员(member): Members.Login("username", "password"); 通过电子邮件拉成员(member): Members.GetByEmail("email"); // returns IPublishedContentUmbraco.Web.Security.MembershipHelper的完整公共(public)接口(interface)类(class):
      /// <summary> A helper class for handling Members </summary>
      public class MembershipHelper
      {
        public MembershipHelper(ApplicationContext applicationContext, HttpContextBase httpContext);
        public MembershipHelper(UmbracoContext umbracoContext);
    
        /// <summary> Returns true if the current membership provider is the Umbraco built-in one. </summary>
        public bool IsUmbracoMembershipProviderActive();
    
        /// <summary> Updates the currently logged in members profile </summary>
        /// <returns> The updated MembershipUser object </returns>
        public Attempt<MembershipUser> UpdateMemberProfile(ProfileModel model);
    
        /// <summary> Registers a new member </summary>
        /// <param name="model"/><param name="status"/>
        /// <param name="logMemberIn">true to log the member in upon successful registration </param>
        public MembershipUser RegisterMember(RegisterModel model, out MembershipCreateStatus status, bool logMemberIn = true);
    
        /// A helper method to perform the validation and logging in of a member - this is simply wrapping standard membership provider and asp.net forms auth logic.
        public bool Login(string username, string password);
    
        /// <summary> Logs out the current member </summary>
        public void Logout();
    
        public IPublishedContent GetByProviderKey(object key);
        public IPublishedContent GetById(int memberId);
        public IPublishedContent GetByUsername(string username);
        public IPublishedContent GetByEmail(string email);
    
        /// <summary> Returns the currently logged in member as IPublishedContent </summary>
        public IPublishedContent GetCurrentMember();
    
        /// <summary> Returns the currently logged in member id, -1 if they are not logged in </summary>
        public int GetCurrentMemberId();
    
        /// Creates a new profile model filled in with the current members details if they are logged in which allows for editing
        ///             profile properties
        public ProfileModel GetCurrentMemberProfileModel();
    
        /// Creates a model to use for registering new members with custom member properties
        public RegisterModel CreateRegistrationModel(string memberTypeAlias = null);
    
        /// Returns the login status model of the currently logged in member, if no member is logged in it returns null;
        public LoginStatusModel GetCurrentLoginStatus();
    
        /// <summary> Check if a member is logged in </summary>
        public bool IsLoggedIn();
    
        /// Returns true or false if the currently logged in member is authorized based on the parameters provided
        public bool IsMemberAuthorized(bool allowAll = false, IEnumerable<string> allowTypes = null, IEnumerable<string> allowGroups = null, IEnumerable<int> allowMembers = null);
    
        /// Changes password for a member/user given the membership provider and the password change model
        public Attempt<PasswordChangedModel> ChangePassword(string username, ChangingPasswordModel passwordModel, string membershipProviderName);
        public Attempt<PasswordChangedModel> ChangePassword(string username, ChangingPasswordModel passwordModel, MembershipProvider membershipProvider);
      }
    

    关于在 Umbraco 7 上以编程方式登录成员(member),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27704219/

    相关文章:

    c# - 在 Bootstrap 中对齐列。第一个瓷砖需要大

    Umbraco - Xml 缓存已损坏。使用 Health Check 数据完整性仪表板修复它

    umbraco - 在 Umbraco 7 中按名称或哈希获取媒体文件夹

    subdomain - 我需要 umbraco 网站上的子域名

    Django登录应用教程问题

    ios - iOS Shopify中的登录/注册API实现

    php - PHP注册错误

    c# - Umbraco v6.1 的 FileSystemProvider

    azure - Windows Server 2012 (Azure) 上的 Umbraco 7.1.9

    php - 创建一个简单的基于 PHP 和 MYSQL 的登录系统