Adding optional isApproved parameter instead of hardcoding 'true' value

This commit is contained in:
gmargol
2016-11-03 11:21:53 +00:00
parent ef38808ba5
commit bab4c7715d
5 changed files with 16 additions and 12 deletions

View File

@@ -96,7 +96,8 @@ namespace Umbraco.Core.Models
/// The password value passed in to this parameter should be the encoded/encrypted/hashed format of the member's password
/// </param>
/// <param name="contentType"></param>
public Member(string name, string email, string username, string rawPasswordValue, IMemberType contentType)
/// <param name="isApproved">Optional IsApproved parameter</param>
public Member(string name, string email, string username, string rawPasswordValue, IMemberType contentType, bool isApproved = true)
: base(name, -1, contentType, new PropertyCollection())
{
Mandate.ParameterNotNull(contentType, "contentType");
@@ -106,7 +107,7 @@ namespace Umbraco.Core.Models
_email = email;
_username = username;
_rawPasswordValue = rawPasswordValue;
IsApproved = true;
IsApproved = isApproved;
}
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();

View File

@@ -69,8 +69,9 @@ namespace Umbraco.Core.Services
/// <param name="email">Email of the <see cref="IMembershipUser"/> to create</param>
/// <param name="passwordValue">This value should be the encoded/encrypted/hashed value for the password that will be stored in the database</param>
/// <param name="memberTypeAlias">Alias of the Type</param>
/// <param name="isApproved">IsApproved of the <see cref="IMembershipUser"/> to create</param>
/// <returns><see cref="IMembershipUser"/></returns>
T CreateWithIdentity(string username, string email, string passwordValue, string memberTypeAlias);
T CreateWithIdentity(string username, string email, string passwordValue, string memberTypeAlias, bool isApproved = true);
/// <summary>
/// Gets an <see cref="IMembershipUser"/> by its provider key

View File

@@ -830,10 +830,10 @@ namespace Umbraco.Core.Services
/// <param name="passwordValue">This value should be the encoded/encrypted/hashed value for the password that will be stored in the database</param>
/// <param name="memberTypeAlias">Alias of the Type</param>
/// <returns><see cref="IMember"/></returns>
IMember IMembershipMemberService<IMember>.CreateWithIdentity(string username, string email, string passwordValue, string memberTypeAlias)
IMember IMembershipMemberService<IMember>.CreateWithIdentity(string username, string email, string passwordValue, string memberTypeAlias, bool isApproved)
{
var memberType = FindMemberTypeByAlias(memberTypeAlias);
return CreateMemberWithIdentity(username, email, username, passwordValue, memberType);
return CreateMemberWithIdentity(username, email, username, passwordValue, memberType, isApproved);
}
/// <summary>
@@ -846,12 +846,13 @@ namespace Umbraco.Core.Services
/// <param name="name">Name of the Member to create</param>
/// <param name="passwordValue">This value should be the encoded/encrypted/hashed value for the password that will be stored in the database</param>
/// <param name="memberType">MemberType the Member should be based on</param>
/// <param name="isApproved">Optional IsApproved of the Member to create</param>
/// <returns><see cref="IMember"/></returns>
private IMember CreateMemberWithIdentity(string username, string email, string name, string passwordValue, IMemberType memberType)
private IMember CreateMemberWithIdentity(string username, string email, string name, string passwordValue, IMemberType memberType, bool isApproved = true)
{
if (memberType == null) throw new ArgumentNullException("memberType");
var member = new Member(name, email.ToLower().Trim(), username, passwordValue, memberType);
var member = new Member(name, email.ToLower().Trim(), username, passwordValue, memberType, isApproved);
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMember>(member), this))
{

View File

@@ -100,7 +100,7 @@ namespace Umbraco.Core.Services
/// <param name="passwordValue">This value should be the encoded/encrypted/hashed value for the password that will be stored in the database</param>
/// <param name="memberTypeAlias">Alias of the Type</param>
/// <returns><see cref="IUser"/></returns>
IUser IMembershipMemberService<IUser>.CreateWithIdentity(string username, string email, string passwordValue, string memberTypeAlias)
IUser IMembershipMemberService<IUser>.CreateWithIdentity(string username, string email, string passwordValue, string memberTypeAlias, bool isApproved = true)
{
var userType = GetUserTypeByAlias(memberTypeAlias);
if (userType == null)
@@ -120,8 +120,9 @@ namespace Umbraco.Core.Services
/// <param name="email">Email of the Member to create</param>
/// <param name="passwordValue">This value should be the encoded/encrypted/hashed value for the password that will be stored in the database</param>
/// <param name="userType">MemberType the Member should be based on</param>
/// <param name="isApproved">Optional IsApproved parameter</param>
/// <returns><see cref="IUser"/></returns>
private IUser CreateUserWithIdentity(string username, string email, string passwordValue, IUserType userType)
private IUser CreateUserWithIdentity(string username, string email, string passwordValue, IUserType userType, bool isApproved = true)
{
if (userType == null) throw new ArgumentNullException("userType");
@@ -145,7 +146,7 @@ namespace Umbraco.Core.Services
StartContentId = -1,
StartMediaId = -1,
IsLockedOut = false,
IsApproved = true
IsApproved = isApproved
};
//adding default sections content and media
user.AddAllowedSection("content");

View File

@@ -166,11 +166,11 @@ namespace Umbraco.Web.Security.Providers
username,
email,
FormatPasswordForStorage(encodedPassword, salt),
memberTypeAlias);
memberTypeAlias,
isApproved);
member.PasswordQuestion = passwordQuestion;
member.RawPasswordAnswerValue = EncryptString(passwordAnswer);
member.IsApproved = isApproved;
member.LastLoginDate = DateTime.Now;
member.LastPasswordChangeDate = DateTime.Now;