diff --git a/IdentityDbContext.cs b/IdentityDbContext.cs new file mode 100644 index 0000000..9100274 --- /dev/null +++ b/IdentityDbContext.cs @@ -0,0 +1,125 @@ +using System; +using System.Configuration; +using System.Linq; +using MongoDB.Driver; + +namespace MongoDB.AspNet.Identity +{ + public class IdentityDbContext : IdentityDbContext + where TUser : IdentityUser + { + public IdentityDbContext() : this("DefaultConnection") { } + public IdentityDbContext(string nameOrConnectionString) : base(nameOrConnectionString) { } + } + + public class IdentityDbContext : IdentityDbContext + { + public IdentityDbContext() : this("DefaultConnection") { } + public IdentityDbContext(string nameOrConnectionString) : base(nameOrConnectionString) { } + } + + public class IdentityDbContext : IDisposable + where TUser : IdentityUser + where TRole : IdentityRole + where TUserLogin : IdentityUserLogin + where TUserRole : IdentityUserRole + where TUserClaim : IdentityUserClaim + { + + internal readonly MongoDatabase db; + + public MongoDatabase Context { get { return db; } } + + + /// + /// Gets the database from connection string. + /// + /// The connection string. + /// MongoDatabase. + /// No database name specified in connection string + private MongoDatabase GetDatabaseFromSqlStyle(string connectionString) + { + var conString = new MongoConnectionStringBuilder(connectionString); + MongoClientSettings settings = MongoClientSettings.FromConnectionStringBuilder(conString); + MongoServer server = new MongoClient(settings).GetServer(); + if (conString.DatabaseName == null) + { + throw new Exception("No database name specified in connection string"); + } + return server.GetDatabase(conString.DatabaseName); + } + + /// + /// Gets the database from URL. + /// + /// The URL. + /// MongoDatabase. + private MongoDatabase GetDatabaseFromUrl(MongoUrl url) + { + var client = new MongoClient(url); + MongoServer server = client.GetServer(); + if (url.DatabaseName == null) + { + throw new Exception("No database name specified in connection string"); + } + return server.GetDatabase(url.DatabaseName); // WriteConcern defaulted to Acknowledged + } + + /// + /// Uses connectionString to connect to server and then uses databae name specified. + /// + /// The connection string. + /// Name of the database. + /// MongoDatabase. + private MongoDatabase GetDatabase(string connectionString, string dbName) + { + var client = new MongoClient(connectionString); + MongoServer server = client.GetServer(); + return server.GetDatabase(dbName); + } + + public bool RequireUniqueEmail + { + get; + set; + } + + public virtual IQueryable Roles + { + get; + set; + } + + public virtual IQueryable Users + { + get; + set; + } + + public IdentityDbContext() : this("DefaultConnection") { } + public IdentityDbContext(string nameOrConnectionString) + { + if (nameOrConnectionString.ToLower().StartsWith("mongodb://")) + { + db = GetDatabaseFromUrl(new MongoUrl(nameOrConnectionString)); + } + else + { + string connStringFromManager = + ConfigurationManager.ConnectionStrings[nameOrConnectionString].ConnectionString; + if (connStringFromManager.ToLower().StartsWith("mongodb://")) + { + db = GetDatabaseFromUrl(new MongoUrl(connStringFromManager)); + } + else + { + db = GetDatabaseFromSqlStyle(connStringFromManager); + } + } + } + + public void Dispose() + { + } + } +} \ No newline at end of file diff --git a/IdentityRole.cs b/IdentityRole.cs new file mode 100644 index 0000000..3a6494c --- /dev/null +++ b/IdentityRole.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using Microsoft.AspNet.Identity; + +namespace MongoDB.AspNet.Identity +{ + public class IdentityRole : IdentityRole + { + public IdentityRole() + { + base.Id = Guid.NewGuid().ToString(); + } + + public IdentityRole(string roleName) + : this() + { + base.Name = roleName; + } + } + + + public class IdentityRole : IRole + where TUserRole : IdentityUserRole + { + public TKey Id { get; set; } + public string Name { get; set; } + + public ICollection Users { get; set; } + + public virtual ICollection GetUsers() + { + return Users; + } + + public IdentityRole() + { + Users = new List(); + } + + } +} \ No newline at end of file diff --git a/IdentityUser.cs b/IdentityUser.cs index aa31b8c..71ba170 100644 --- a/IdentityUser.cs +++ b/IdentityUser.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Microsoft.AspNet.Identity; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; @@ -6,97 +7,144 @@ namespace MongoDB.AspNet.Identity { + /// /// Class IdentityUser. /// - public class IdentityUser : IUser + public class IdentityUser : IdentityUser, IUser, IUser { /// - /// Unique key for the user + /// Initializes a new instance of the class. + /// + public IdentityUser() {} + + /// + /// Initializes a new instance of the class. + /// + /// Name of the user. + public IdentityUser(string userName) : this() + { + this.UserName = userName; + } + } + + /// + /// Class IdentityUser. + /// + public class IdentityUser : IUser + where TLogin : IdentityUserLogin + where TRole : IdentityUserRole + where TClaim : IdentityUserClaim + { + /// + /// Unique key for the user. TKey must be a string. /// /// The identifier. /// The unique key for the user [BsonId] [BsonRepresentation(BsonType.ObjectId)] - public virtual string Id { get; set; } + public virtual TKey Id { get; set; } + /// /// Gets or sets the name of the user. /// /// The name of the user. - public virtual string UserName { get; set; } + public virtual string UserName { get; set; } + /// /// Gets or sets the password hash. /// /// The password hash. - public virtual string PasswordHash { get; set; } + public virtual string PasswordHash { get; set; } + /// /// Gets or sets the security stamp. /// /// The security stamp. - public virtual string SecurityStamp { get; set; } + public virtual string SecurityStamp { get; set; } + /// - /// Gets the roles. + /// Gets the roles. Extended from the AspNet IdentityUser entity to add a Role array to the users to follow a more Mongo document model style. /// /// The roles. - public virtual List Roles { get; private set; } + public virtual List Roles { get; private set; } + + /// + /// Gets or sets the roles. Matches the AspNet IdentityUser entity signature. + /// + /// The roles. + //public virtual ICollection Roles { get; set; } + /// /// Gets the claims. /// /// The claims. - public virtual List Claims { get; private set; } + public virtual List Claims { get; private set; } + /// /// Gets the logins. /// /// The logins. - public virtual List Logins { get; private set; } + public virtual List Logins { get; private set; } /// - /// Initializes a new instance of the class. + /// Gets or sets a value indicating whether [two factor enabled]. /// - public IdentityUser() - { - this.Claims = new List(); - this.Roles = new List(); - this.Logins = new List(); - } + /// true if [two factor enabled]; otherwise, false. + public virtual bool TwoFactorEnabled { get; set; } /// - /// Initializes a new instance of the class. + /// Gets or sets the phone number. /// - /// Name of the user. - public IdentityUser(string userName) : this() - { - this.UserName = userName; - } - } + /// The phone number. + public virtual string PhoneNumber { get; set; } - /// - /// Class IdentityUserClaim. - /// - public class IdentityUserClaim - { /// - /// Gets or sets the identifier. + /// Gets or sets a value indicating whether [phone number confirmed]. /// - /// The identifier. - [BsonId] - [BsonRepresentation(BsonType.ObjectId)] - public virtual string Id { get; set; } + /// true if [phone number confirmed]; otherwise, false. + public virtual bool PhoneNumberConfirmed { get; set; } + /// - /// Gets or sets the user identifier. + /// Gets or sets the email. /// - /// The user identifier. - public virtual string UserId { get; set; } + /// The email. + public virtual string Email { get; set; } + /// - /// Gets or sets the type of the claim. + /// Gets or sets a value indicating whether [email confirmed]. /// - /// The type of the claim. - public virtual string ClaimType { get; set; } + /// true if [email confirmed]; otherwise, false. + public virtual bool EmailConfirmed { get; set; } + /// - /// Gets or sets the claim value. + /// Gets or sets the access failed count. /// - /// The claim value. - public virtual string ClaimValue { get; set; } - - } + /// The access failed count. + public virtual int AccessFailedCount { get; set; } + + /// + /// Gets or sets a value indicating whether [lockout enabled]. + /// + /// true if [lockout enabled]; otherwise, false. + public virtual bool LockoutEnabled { get; set; } + + /// + /// Gets or sets the lockout end date UTC. + /// + /// The lockout end date UTC. + public virtual DateTime? LockoutEndDateUtc { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public IdentityUser() + { + //this.Id = Guid.NewGuid().ToString(); + this.Claims = new List(); + this.Roles = new List(); + this.Logins = new List(); + } + } + } diff --git a/IdentityUserClaim.cs b/IdentityUserClaim.cs new file mode 100644 index 0000000..7b55c7a --- /dev/null +++ b/IdentityUserClaim.cs @@ -0,0 +1,46 @@ +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; + +namespace MongoDB.AspNet.Identity +{ + + + /// + /// Class IdentityUserClaim. + /// + public class IdentityUserClaim : IdentityUserClaim + { + + } + + /// + /// Class IdentityUserClaim. + /// + public class IdentityUserClaim + { + /// + /// Gets or sets the identifier. + /// + /// The identifier. + [BsonId] + [BsonRepresentation(BsonType.ObjectId)] + public virtual string Id { get; set; } + /// + /// Gets or sets the user identifier. + /// + /// The user identifier. + public virtual TKey UserId { get; set; } + /// + /// Gets or sets the type of the claim. + /// + /// The type of the claim. + public virtual string ClaimType { get; set; } + /// + /// Gets or sets the claim value. + /// + /// The claim value. + public virtual string ClaimValue { get; set; } + + + } +} \ No newline at end of file diff --git a/IdentityUserLogin.cs b/IdentityUserLogin.cs new file mode 100644 index 0000000..043b8b2 --- /dev/null +++ b/IdentityUserLogin.cs @@ -0,0 +1,34 @@ +namespace MongoDB.AspNet.Identity +{ + public class IdentityUserLogin : IdentityUserLogin + { + public IdentityUserLogin() + { + } + } + + public class IdentityUserLogin + { + public virtual string LoginProvider + { + get; + set; + } + + public virtual string ProviderKey + { + get; + set; + } + + public virtual TKey UserId + { + get; + set; + } + + public IdentityUserLogin() + { + } + } +} \ No newline at end of file diff --git a/IdentityUserRole.cs b/IdentityUserRole.cs new file mode 100644 index 0000000..905a2f8 --- /dev/null +++ b/IdentityUserRole.cs @@ -0,0 +1,30 @@ +namespace MongoDB.AspNet.Identity +{ + + + public class IdentityUserRole : IdentityUserRole + { + public IdentityUserRole() + { + } + } + + public class IdentityUserRole + { + public virtual TKey RoleId + { + get; + set; + } + + public virtual TKey UserId + { + get; + set; + } + + public IdentityUserRole() + { + } + } +} \ No newline at end of file diff --git a/MongoDB.AspNet.Identity.csproj b/MongoDB.AspNet.Identity.csproj index ba38609..f933717 100644 --- a/MongoDB.AspNet.Identity.csproj +++ b/MongoDB.AspNet.Identity.csproj @@ -41,16 +41,17 @@ bin\MongoDB.AspNet.Identity.XML - - packages\Microsoft.AspNet.Identity.Core.1.0.0\lib\net45\Microsoft.AspNet.Identity.Core.dll + + False + ..\Test.MongoDB.AspNet.Identity\packages\Microsoft.AspNet.Identity.Core.2.0.1\lib\net45\Microsoft.AspNet.Identity.Core.dll - + False - packages\mongocsharpdriver.1.8.3\lib\net35\MongoDB.Bson.dll + ..\Test.MongoDB.AspNet.Identity\packages\mongocsharpdriver.1.9.1\lib\net35\MongoDB.Bson.dll - + False - packages\mongocsharpdriver.1.8.3\lib\net35\MongoDB.Driver.dll + ..\Test.MongoDB.AspNet.Identity\packages\mongocsharpdriver.1.9.1\lib\net35\MongoDB.Driver.dll @@ -64,8 +65,14 @@ + + + + + + diff --git a/RoleStore.cs b/RoleStore.cs new file mode 100644 index 0000000..74f75aa --- /dev/null +++ b/RoleStore.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using System.Web; +using Microsoft.AspNet.Identity; +using MongoDB.Bson; +using MongoDB.Driver; +using MongoDB.Driver.Builders; + +namespace MongoDB.AspNet.Identity +{ + + + public class RoleStore : RoleStore, IQueryableRoleStore, IQueryableRoleStore, IRoleStore, IDisposable + where TRole : IdentityRole, new() + { + public RoleStore() : base(new IdentityDbContext().db) { } + } + + public class RoleStore : IQueryableRoleStore, IRoleStore, IDisposable + where TRole : IdentityRole, new() + where TUserRole : IdentityUserRole, new() + { + private bool _disposed; + + private readonly MongoDatabase db; + private const string collectionName = "AspNetRoles"; + + + public RoleStore(MongoDatabase context) + { + db = context; + } + + public bool DisposeContext + { + get; + set; + } + + public IQueryable Roles + { + get { return db.GetCollection(collectionName).FindAll().AsQueryable(); } + } + + + public virtual async Task CreateAsync(TRole role) + { + this.ThrowIfDisposed(); + if (role == null) + { + throw new ArgumentNullException("role"); + } + + db.GetCollection(collectionName).Insert(role); + + } + + public virtual async Task DeleteAsync(TRole role) + { + this.ThrowIfDisposed(); + if (role == null) + { + throw new ArgumentNullException("role"); + } + + db.GetCollection(collectionName).Remove((Query.EQ("_id", ObjectId.Parse(role.Id.ToString())))); + } + + public void Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + _disposed = true; + } + + public Task FindByIdAsync(TKey roleId) + { + this.ThrowIfDisposed(); + TRole role = db.GetCollection(collectionName).FindOne((Query.EQ("_id", ObjectId.Parse(roleId.ToString())))); + return Task.FromResult(role); + } + + public Task FindByNameAsync(string roleName) + { + this.ThrowIfDisposed(); + TRole role = db.GetCollection(collectionName).FindOne((Query.EQ("Name", roleName))); + return Task.FromResult(role); + } + + private void ThrowIfDisposed() + { + if (this._disposed) + { + throw new ObjectDisposedException(this.GetType().Name); + } + } + + public virtual async Task UpdateAsync(TRole role) + { + this.ThrowIfDisposed(); + if (role == null) + { + throw new ArgumentNullException("role"); + } + + db.GetCollection(collectionName).Update(Query.EQ("_id", ObjectId.Parse(role.Id.ToString())), Update.Replace(role), UpdateFlags.Upsert); + + + } + } +} \ No newline at end of file diff --git a/UserStore.cs b/UserStore.cs index 93613eb..bd5dded 100644 --- a/UserStore.cs +++ b/UserStore.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Configuration; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; @@ -11,16 +10,49 @@ namespace MongoDB.AspNet.Identity { + + /// + /// Class UserStore. + /// + /// The type of the t user. + public class UserStore : UserStore, IUserStore, IUserStore, IDisposable + where TUser : IdentityUser + { + /// + /// Initializes a new instance of the class. + /// + /// The context. + public UserStore(IdentityDbContext context) : base(context.db) { } + /// + /// Initializes a new instance of the class. + /// + /// The database. + public UserStore(MongoDatabase db) : base(db) { } + } + + + /// - /// Class UserStore. + /// Class UserStore. /// /// The type of the t user. - public class UserStore : IUserLoginStore, IUserClaimStore, IUserRoleStore, - IUserPasswordStore, IUserSecurityStampStore - where TUser : IdentityUser + /// The type of the t role. + /// The type of the t key. + /// The type of the t user login. + /// The type of the t user role. + /// The type of the t user claim. + public class UserStore : IUserLoginStore, IUserClaimStore, IUserRoleStore, IUserPasswordStore, IUserSecurityStampStore, IQueryableUserStore, IUserEmailStore, IUserPhoneNumberStore, IUserTwoFactorStore, IUserStore, IDisposable + where TUser : IdentityUser + where TRole : IdentityRole + where TKey : IEquatable + where TUserLogin : IdentityUserLogin, new() + where TUserRole : IdentityUserRole, new() + where TUserClaim : IdentityUserClaim, new() { #region Private Methods & Variables + + /// /// The database /// @@ -36,140 +68,26 @@ public class UserStore : IUserLoginStore, IUserClaimStore, /// private const string collectionName = "AspNetUsers"; - /// - /// Gets the database from connection string. - /// - /// The connection string. - /// MongoDatabase. - /// No database name specified in connection string - private MongoDatabase GetDatabaseFromSqlStyle(string connectionString) - { - var conString = new MongoConnectionStringBuilder(connectionString); - MongoClientSettings settings = MongoClientSettings.FromConnectionStringBuilder(conString); - MongoServer server = new MongoClient(settings).GetServer(); - if (conString.DatabaseName == null) - { - throw new Exception("No database name specified in connection string"); - } - return server.GetDatabase(conString.DatabaseName); - } - - /// - /// Gets the database from URL. - /// - /// The URL. - /// MongoDatabase. - private MongoDatabase GetDatabaseFromUrl(MongoUrl url) - { - var client = new MongoClient(url); - MongoServer server = client.GetServer(); - if (url.DatabaseName == null) - { - throw new Exception("No database name specified in connection string"); - } - return server.GetDatabase(url.DatabaseName); // WriteConcern defaulted to Acknowledged - } - - /// - /// Uses connectionString to connect to server and then uses databae name specified. - /// - /// The connection string. - /// Name of the database. - /// MongoDatabase. - private MongoDatabase GetDatabase(string connectionString, string dbName) - { - var client = new MongoClient(connectionString); - MongoServer server = client.GetServer(); - return server.GetDatabase(dbName); - } #endregion #region Constructors - - /// - /// Initializes a new instance of the class. Uses DefaultConnection name if none was - /// specified. - /// - public UserStore() : this("DefaultConnection") - { - } /// - /// Initializes a new instance of the class. Uses name from ConfigurationManager or a - /// mongodb:// Url. + /// Initializes a new instance of the class. /// - /// The connection name or URL. - public UserStore(string connectionNameOrUrl) - { - if (connectionNameOrUrl.ToLower().StartsWith("mongodb://")) - { - db = GetDatabaseFromUrl(new MongoUrl(connectionNameOrUrl)); - } - else - { - string connStringFromManager = - ConfigurationManager.ConnectionStrings[connectionNameOrUrl].ConnectionString; - if (connStringFromManager.ToLower().StartsWith("mongodb://")) - { - db = GetDatabaseFromUrl(new MongoUrl(connStringFromManager)); - } - else - { - db = GetDatabaseFromSqlStyle(connStringFromManager); - } - } - } + public UserStore(): this(new IdentityDbContext().db) {} /// - /// Initializes a new instance of the class. Uses name from ConfigurationManager or a - /// mongodb:// Url. - /// Database can be specified separately from connection server. + /// Initializes a new instance of the class. /// - /// The connection name or URL. - /// Name of the database. - public UserStore(string connectionNameOrUrl, string dbName) + /// The context. + public UserStore(MongoDatabase context) { - if (connectionNameOrUrl.ToLower().StartsWith("mongodb://")) - { - db = GetDatabase(connectionNameOrUrl, dbName); - } - else - { - db = GetDatabase(ConfigurationManager.ConnectionStrings[connectionNameOrUrl].ConnectionString, dbName); - } - } - - /// - /// Initializes a new instance of the class using a already initialized Mongo Database. - /// - /// The mongo database. - public UserStore(MongoDatabase mongoDatabase) - { - db = mongoDatabase; + db = context; } - /// - /// Initializes a new instance of the class. - /// - /// Name of the connection from ConfigurationManager.ConnectionStrings[]. - /// if set to true [use mongo URL format]. - [Obsolete("Use UserStore(connectionNameOrUrl)")] - public UserStore(string connectionName, bool useMongoUrlFormat) - { - string connectionString = ConfigurationManager.ConnectionStrings[connectionName].ConnectionString; - if (useMongoUrlFormat) - { - var url = new MongoUrl(connectionString); - db = GetDatabaseFromUrl(url); - } - else - { - db = GetDatabaseFromSqlStyle(connectionString); - } - } - #endregion #region Methods @@ -263,10 +181,22 @@ public Task DeleteAsync(TUser user) if (user == null) throw new ArgumentNullException("user"); - db.GetCollection(collectionName).Remove((Query.EQ("_id", ObjectId.Parse(user.Id)))); + db.GetCollection(collectionName).Remove((Query.EQ("_id", ObjectId.Parse(user.Id.ToString())))); return Task.FromResult(true); } + /// + /// Finds the by identifier asynchronous. + /// + /// The user identifier. + /// Task{`0}. + public Task FindByIdAsync(TKey userId) + { + ThrowIfDisposed(); + TUser user = db.GetCollection(collectionName).FindOne((Query.EQ("_id", ObjectId.Parse(userId.ToString())))); + return Task.FromResult(user); + } + /// /// Finds the by identifier asynchronous. /// @@ -292,6 +222,70 @@ public Task FindByNameAsync(string userName) return Task.FromResult(user); } + /// + /// Sets the email confirmed asynchronous. + /// + /// The user. + /// if set to true [confirmed]. + /// Task. + /// + public Task SetEmailConfirmedAsync(TUser user, bool confirmed) + { + throw new NotImplementedException(); + } + + /// + /// Finds the by email asynchronous. + /// + /// The email. + /// Task{`0}. + public Task FindByEmailAsync(string email) + { + ThrowIfDisposed(); + + TUser user = db.GetCollection(collectionName).FindOne((Query.EQ("Email", email))); + return Task.FromResult(user); + } + + /// + /// Sets the email asynchronous. + /// + /// The user. + /// The email. + /// Task. + /// + public Task SetEmailAsync(TUser user, string email) + { + throw new NotImplementedException(); + } + + /// + /// Gets the email asynchronous. + /// + /// The user. + /// Task{System.String}. + /// user + public Task GetEmailAsync(TUser user) + { + ThrowIfDisposed(); + if (user == null) + { + throw new ArgumentException("user"); + } + return Task.FromResult(user.Email); + } + + /// + /// Gets the email confirmed asynchronous. + /// + /// The user. + /// Task{System.Boolean}. + /// + public Task GetEmailConfirmedAsync(TUser user) + { + throw new NotImplementedException(); + } + /// /// Updates the user asynchronous. /// @@ -304,8 +298,7 @@ public Task UpdateAsync(TUser user) if (user == null) throw new ArgumentNullException("user"); - db.GetCollection(collectionName) - .Update(Query.EQ("_id", ObjectId.Parse(user.Id)), Update.Replace(user), UpdateFlags.Upsert); + db.GetCollection(collectionName).Update(Query.EQ("_id", ObjectId.Parse(user.Id.ToString())), Update.Replace(user), UpdateFlags.Upsert); return Task.FromResult(user); } @@ -544,6 +537,116 @@ private void ThrowIfDisposed() } #endregion + + /// + /// Gets the users. + /// + /// The users. + public IQueryable Users { get; private set; } + + /// + /// Sets the phone number asynchronous. + /// + /// The user. + /// The phone number. + /// Task. + /// user + public Task SetPhoneNumberAsync(TUser user, string phoneNumber) + { + ThrowIfDisposed(); + if (user == null) + { + throw new ArgumentException("user"); + } + + user.PhoneNumber = phoneNumber; + return Task.FromResult(0); + } + + /// + /// Gets the phone number asynchronous. + /// + /// The user. + /// Task{System.String}. + /// user + public Task GetPhoneNumberAsync(TUser user) + { + ThrowIfDisposed(); + if (user == null) + { + throw new ArgumentNullException("user"); + } + + return Task.FromResult(user.PhoneNumber); + } + + /// + /// Gets the phone number confirmed asynchronous. + /// + /// The user. + /// Task{System.Boolean}. + /// user + public Task GetPhoneNumberConfirmedAsync(TUser user) + { + ThrowIfDisposed(); + if (user == null) + { + throw new ArgumentNullException("user"); + } + return Task.FromResult(user.PhoneNumberConfirmed); + } + + /// + /// Sets the phone number confirmed asynchronous. + /// + /// The user. + /// if set to true [confirmed]. + /// Task. + /// user + public Task SetPhoneNumberConfirmedAsync(TUser user, bool confirmed) + { + ThrowIfDisposed(); + if (user == null) + { + throw new ArgumentNullException("user"); + } + user.PhoneNumberConfirmed = confirmed; + return Task.FromResult(0); + } + + /// + /// Sets the two factor enabled asynchronous. + /// + /// The user. + /// if set to true [enabled]. + /// Task. + /// user + public Task SetTwoFactorEnabledAsync(TUser user, bool enabled) + { + ThrowIfDisposed(); + if (user == null) + { + throw new ArgumentNullException("user"); + } + user.TwoFactorEnabled = enabled; + return Task.FromResult(0); + } + + /// + /// Gets the two factor enabled asynchronous. + /// + /// The user. + /// Task{System.Boolean}. + /// user + public Task GetTwoFactorEnabledAsync(TUser user) + { + ThrowIfDisposed(); + if (user == null) + { + throw new ArgumentNullException("user"); + } + return Task.FromResult(user.TwoFactorEnabled); + } } } \ No newline at end of file diff --git a/Utils.cs b/Utils.cs index addfa5a..6601cee 100644 --- a/Utils.cs +++ b/Utils.cs @@ -1,5 +1,7 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; +using MongoDB.Driver; namespace MongoDB.AspNet.Identity { @@ -15,5 +17,6 @@ internal static IList ToIList(this IEnumerable enumerable) { return enumerable.ToList(); } + } } \ No newline at end of file diff --git a/packages.config b/packages.config index 0e77e46..a0f639e 100644 --- a/packages.config +++ b/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file