当前位置: 首页>>代码示例>>C#>>正文


C# Context.AppActiveUsers方法代码示例

本文整理汇总了C#中Context.AppActiveUsers方法的典型用法代码示例。如果您正苦于以下问题:C# Context.AppActiveUsers方法的具体用法?C# Context.AppActiveUsers怎么用?C# Context.AppActiveUsers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Context的用法示例。


在下文中一共展示了Context.AppActiveUsers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetUser

 public override Sys.MembershipUser GetUser(object providerUserKey, bool userIsOnline)
 {
     if (!(providerUserKey is Guid)) throw new InvalidOperationException("No Guid providerUserKey");
     var uid = (Guid)providerUserKey;
     using (var db = new Context()) {
         var user = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.UserId == uid);
         if (user != null) {
             if (userIsOnline) {
                 user.LastActivityDate = DateTime.UtcNow;
                 db.SaveChanges();
             }
             return user.MembershipUser;
         }
     }
     return null;
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:16,代码来源:MembershipProvider.cs

示例2: GetUserIdFromPasswordResetToken

 public override System.Guid GetUserIdFromPasswordResetToken(string token)
 {
     if (string.IsNullOrEmpty(token)) {
         throw CreateArgumentNullOrEmptyException("token");
     }
     using (var db = new Context()) {
         var result = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.PasswordVerificationToken == token);
         if (result != null) {
             return result.UserId;
         }
         return Guid.Empty;
     }
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:13,代码来源:MembershipProvider.cs

示例3: ConfirmAccount

 public override bool ConfirmAccount(string accountConfirmationToken)
 {
     if (string.IsNullOrEmpty(accountConfirmationToken)) {
         throw CreateArgumentNullOrEmptyException("accountConfirmationToken");
     }
     using (var db = new Context()) {
         try {
             var row = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.ConfirmationToken == accountConfirmationToken);
             if (row != null) {
                 row.IsConfirmed = true;
                 // row.LastActivityDate = DateTime.UtcNow;
                 db.SaveChanges();
                 return true;
             }
         } catch { }
         return false;
     }
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:18,代码来源:MembershipProvider.cs

示例4: UnlockUser

 public override bool UnlockUser(string username)
 {
     if (string.IsNullOrEmpty(username)) throw CreateArgumentNullOrEmptyException("username");
     using (var db = new Context()) {
         var user = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.UserName == username);
         if (user != null && user.IsLockedOut) {
             user.IsLockedOut = false;
             db.SaveChanges();
             return true;
         }
     }
     return false;
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:13,代码来源:MembershipProvider.cs

示例5: ValidateUser

 public override bool ValidateUser(string username, string password)
 {
     if (string.IsNullOrEmpty(username)) throw CreateArgumentNullOrEmptyException("username");
     using (var db = new Context()) {
         var user = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.UserName == username);
         if (user != null) {
             user.LastActivityDate = DateTime.UtcNow;
             db.SaveChanges();
             return user.CheckPassword(password);
         }
     }
     return false;
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:13,代码来源:MembershipProvider.cs

示例6: GeneratePasswordResetToken

        public override string GeneratePasswordResetToken(string userName, int tokenExpirationInMinutesFromNow)
        {
            if (string.IsNullOrEmpty(userName)) {
                throw CreateArgumentNullOrEmptyException("userName");
            }
            using (var db = new Context()) {
                try {
                    var user = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.UserName == userName);
                    if (user == null) {
                        throw new InvalidOperationException(string.Format("User not found: {0}", userName));
                    }
                    if (!user.IsConfirmed) {
                        throw new InvalidOperationException(string.Format("User not found: {0}", userName));
                    }
                    string token = null;
                    if (user.PasswordVerificationTokenExpirationDate > DateTime.UtcNow) {
                        token = user.PasswordVerificationToken;
                    } else {
                        token = Services.Crypto.GenerateToken();
                    }
                    user.PasswordVerificationToken = token;
                    user.PasswordVerificationTokenExpirationDate = DateTime.UtcNow.AddMinutes(tokenExpirationInMinutesFromNow);

                    // user.LastActivityDate = DateTime.UtcNow;
                    db.SaveChanges();
                    return token;
                } catch {
                    throw new InvalidOperationException(string.Format("User not found: {0}", userName));
                }
            }
        }
开发者ID:simonegli8,项目名称:Silversite,代码行数:31,代码来源:MembershipProvider.cs

示例7: ResetPassword

 public override string ResetPassword(string username, string answer)
 {
     if (string.IsNullOrEmpty(username)) throw CreateArgumentNullOrEmptyException("username");
     using (var db = new Context()) {
         var user = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.UserName == username);
         if (user != null) {
             if (user.CheckAnswer(answer)) {
                 var pwd = GeneratePassword();
                 user.SetPassword(this, pwd);
                 return pwd;
             }
         }
     }
     return null;
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:15,代码来源:MembershipProvider.cs

示例8: FindUsersByEmail

 public override Sys.MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
 {
     using (var db = new Context()) {
         var users = db.AppActiveUsers<MembershipProvider>().Where(u => u.Email == emailToMatch).Skip(pageIndex).Take(pageSize);
         totalRecords = users.Count();
         var collection = new Sys.MembershipUserCollection();
         foreach (var u in users) collection.Add(u.MembershipUser);
         return collection;
     }
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:10,代码来源:MembershipProvider.cs

示例9: FindUsersByName

 public override Sys.MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
 {
     using (var db = new Context()) {
         IEnumerable<User> users;
         if (usernameToMatch.ContainsAny(',', ';', '*')) {
             users = db.AppActiveUsers<MembershipProvider>().AsEnumerable().Where(u => Services.Paths.Match(usernameToMatch, u.UserName));
         } else {
             users = db.AppActiveUsers<MembershipProvider>().Where(u => u.UserName == usernameToMatch);
         }
         users = users.Skip(pageIndex).Take(pageSize);
         totalRecords = users.Count();
         var collection = new Sys.MembershipUserCollection();
         foreach (var u in users) collection.Add(u.MembershipUser);
         return collection;
     }
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:16,代码来源:MembershipProvider.cs

示例10: ExtendedValidateUser

        public override string ExtendedValidateUser(string userNameOrEmail, string password)
        {
            if (string.IsNullOrEmpty(userNameOrEmail)) {
                throw CreateArgumentNullOrEmptyException("userNameOrEmail");
            }
            if (string.IsNullOrEmpty(password)) {
                throw CreateArgumentNullOrEmptyException("password");
            }
            using (var db = new Context()) {
                try {
                    User user = null;
                    user = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.UserName == userNameOrEmail);
                    if (user == null) {
                        user = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.Email == userNameOrEmail);
                    }
                    if (user == null) {
                        return string.Empty;
                    }
                    if (!user.IsConfirmed || !user.IsApproved) {
                        return string.Empty;
                    }

                    bool verificationSucceeded = user.CheckPassword(password);

                    user.LastActivityDate = DateTime.UtcNow;
                    db.SaveChanges();
                    if (verificationSucceeded) {
                        return user.UserName;
                    }
                } catch { }
                return string.Empty;
            }
        }
开发者ID:simonegli8,项目名称:Silversite,代码行数:33,代码来源:MembershipProvider.cs

示例11: CreateUser

        public override Sys.MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out Sys.MembershipCreateStatus status)
        {
            status = Sys.MembershipCreateStatus.Success;

            if (string.IsNullOrEmpty(username)) status = Sys.MembershipCreateStatus.InvalidUserName;
            //if (string.IsNullOrEmpty(email)) status = Sys.MembershipCreateStatus.InvalidEmail;
            if (!ValidPassword(password)) status = Sys.MembershipCreateStatus.InvalidPassword;
            if (RequiresQuestionAndAnswer) {
                if (string.IsNullOrEmpty(passwordQuestion)) status = Sys.MembershipCreateStatus.InvalidQuestion;
                if (string.IsNullOrEmpty(passwordAnswer)) status = Sys.MembershipCreateStatus.InvalidAnswer;
            }

            if (status != Sys.MembershipCreateStatus.Success) return null;

            using (var db = new Context()) {

                try {
                    var user = db.AppUsers<MembershipProvider>().FirstOrDefault(u => u.UserName == username);

                    if (user != null && user.IsDeleted) {
                        db.Users.Remove(user);
                        user = null;
                    }

                    User emailuser = null;
                    if (!string.IsNullOrEmpty(email)) {
                        emailuser = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.Email == email);
                    }
                    if (user != null) status = Sys.MembershipCreateStatus.DuplicateUserName;
                    if (emailuser != null && RequiresUniqueEmail) status = Sys.MembershipCreateStatus.DuplicateEmail;
                    if (status != Sys.MembershipCreateStatus.Success) return null;

                    User NewUser = new User {
                        UserId = Guid.NewGuid(),
                        UserName = username,
                        IsConfirmed = true,
                        Email = email,
                        ConfirmationToken = null,
                        CreationDate = DateTime.UtcNow,
                        PasswordChangedDate = DateTime.UtcNow,
                        PasswordFailuresSinceLastSuccess = 0,
                        AnswerFailuresSinceLastSuccess = 0,
                        LastPasswordFailureDate = null,
                        LastActivityDate = DateTime.UtcNow,
                        LastLoginDate = null,
                        LastLockoutDate = null,
                        PasswordQuestion = passwordQuestion,
                        PasswordAnswer = passwordAnswer,
                        IsApproved = isApproved,
                        Application = Application.Current<MembershipProvider>(db)
                    };
                    if (providerUserKey is Guid) NewUser.UserId = (Guid)providerUserKey;
                    else NewUser.UserId = Guid.NewGuid();

                    NewUser.SetPassword(this, password);

                    db.Users.Add(NewUser);
                    db.SaveChanges();
                    return NewUser.MembershipUser;
                } catch (Exception ex) {
                    status = Sys.MembershipCreateStatus.DuplicateUserName; return null;
                }
            }
        }
开发者ID:simonegli8,项目名称:Silversite,代码行数:64,代码来源:MembershipProvider.cs

示例12: CreateAccount

        public override string CreateAccount(string userName, string password, string email, bool requireConfirmationToken)
        {
            if (string.IsNullOrEmpty(userName)) {
                throw new Sys.MembershipCreateUserException(Sys.MembershipCreateStatus.InvalidUserName);
            }
            /*if (string.IsNullOrEmpty(email)) {
                throw new Sys.MembershipCreateUserException(Sys.MembershipCreateStatus.InvalidEmail);
            }*/
            if (!ValidPassword(password)) throw new Sys.MembershipCreateUserException(Sys.MembershipCreateStatus.InvalidPassword);

            using (var db = new Context()) {
                try {
                    var user = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.UserName == userName);

                    if (user != null && user.IsDeleted) {
                        db.Users.Remove(user);
                        user = null;
                    }

                    User emailuser = null;
                    if (!string.IsNullOrEmpty(email)) {
                        emailuser = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.Email == email);
                    }
                    if (user != null) {
                        throw new Sys.MembershipCreateUserException(Sys.MembershipCreateStatus.DuplicateUserName);
                    }
                    if (emailuser != null && RequiresUniqueEmail) {
                        throw new Sys.MembershipCreateUserException(Sys.MembershipCreateStatus.DuplicateEmail);
                    }
                    string token = null;
                    if (requireConfirmationToken) {
                        token = Services.Crypto.GenerateToken();
                    }

                    User NewUser = new User {
                        UserId = Guid.NewGuid(),
                        UserName = userName,
                        Application = Application.Current<MembershipProvider>(db),
                        IsConfirmed = !requireConfirmationToken,
                        IsApproved = true,
                        Email = email,
                        ConfirmationToken = token,
                        CreationDate = DateTime.UtcNow,
                        PasswordChangedDate = DateTime.UtcNow,
                        PasswordFailuresSinceLastSuccess = 0,
                        AnswerFailuresSinceLastSuccess = 0,
                        LastPasswordFailureDate = null,
                        LastAnswerFailureDate = null,
                        LastActivityDate = DateTime.UtcNow,
                        LastLoginDate = null,
                        LastLockoutDate = null,
                        Comment = null
                    };

                    NewUser.SetPassword(this, password);

                    db.Users.Add(NewUser);
                    db.SaveChanges();
                    return token;
                } catch {
                    throw new Sys.MembershipCreateUserException(Sys.MembershipCreateStatus.DuplicateUserName);
                }
            }
        }
开发者ID:simonegli8,项目名称:Silversite,代码行数:64,代码来源:MembershipProvider.cs

示例13: GetUserNameByEmail

 public override string GetUserNameByEmail(string email)
 {
     if (string.IsNullOrEmpty(email)) throw CreateArgumentNullOrEmptyException("email");
     using (var db = new Context()) {
         var user = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.Email == email);
         if (user != null) return user.UserName;
     }
     return null;
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:9,代码来源:MembershipProvider.cs

示例14: GetAllUsers

 public override Sys.MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
 {
     using (var db = new Context()) {
         var users = db.AppActiveUsers<MembershipProvider>().OrderBy(u => u.UserName).Skip(pageIndex).Take(pageSize);
         totalRecords = users.Count();
         var collection = new Sys.MembershipUserCollection();
         foreach (var u in users) collection.Add(u.MembershipUser);
         return collection;
     }
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:10,代码来源:MembershipProvider.cs

示例15: IsConfirmed

        public override bool IsConfirmed(string userName)
        {
            if (string.IsNullOrEmpty(userName)) {
                throw CreateArgumentNullOrEmptyException("userName");
            }
            using (var db = new Context()) {
                var user = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.UserName == userName);
                if (user == null) {
                    return false;
                }

                // user.LastActivityDate = DateTime.UtcNow;

                if (user.IsConfirmed) {
                    return true;
                } else {
                    return false;
                }
            }
        }
开发者ID:simonegli8,项目名称:Silversite,代码行数:20,代码来源:MembershipProvider.cs


注:本文中的Context.AppActiveUsers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。