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


C# UserRepository.GetByUsername方法代码示例

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


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

示例1: AcceptComment

        public ActionResult AcceptComment(int id)
        {
            AlbumRepository albums = new AlbumRepository();
            CommentModel comment = albums.GetComment(id, true);
            UserRepository users = new UserRepository();
            UserModel user = users.GetByUsername(HttpContext.User.Identity.Name);
            string[] response = new string[2];

            if (user != null)
            {
                if (comment.Album.User.Id == user.Id) //ok
                {
                    response[0] = "ok";
                    response[1] = "";
                    comment.Accepted = true;
                    albums.Update(comment);
                }
                else
                {
                    response[0] = "error";
                    response[1] = "You are not allowed to accept this comment.";
                }
            }
            else
            {
                response[0] = "error";
                response[1] = "You need to be logged in to accept comments";
            }

            return Json(response);
        }
开发者ID:qbajas,项目名称:PhotoHistory,代码行数:31,代码来源:AlbumController.cs

示例2: Activate

        public ActionResult Activate(string user, string token)
        {
            if ( !string.IsNullOrEmpty( user ) && !string.IsNullOrEmpty( token ) )
            {
                UserRepository userRepository = new UserRepository();
                UserModel inactiveUser = userRepository.GetByUsername( user );
                if ( inactiveUser != null && inactiveUser.ActivationCode == token )
                {
                    try
                    {
                        userRepository.Activate( user );
                    }
                    catch ( Exception e )
                    {
                        return HttpNotFound( e.ToString() );
                    }

                    AuthenticateUser( user, false );
                    return RedirectToAction( "Index", "Home" );
                }

                return HttpNotFound( string.Format( "User '{0}' not found or invalid token", user ) );
            }

            return HttpNotFound();
        }
开发者ID:qbajas,项目名称:PhotoHistory,代码行数:26,代码来源:UserController.cs

示例3: IsValid

        public override bool IsValid(object value)
        {
            if ( value != null )
            {
                string password = (string)value;

                UserRepository userRepository = new UserRepository();
                UserModel loggedUser = userRepository.GetByUsername( HttpContext.Current.User.Identity.Name );
                if ( loggedUser == null )
                    throw new Exception( "Logged user entry couldn't be found" );

                return loggedUser.Password == password.HashMD5();
            }

            return false;
        }
开发者ID:qbajas,项目名称:PhotoHistory,代码行数:16,代码来源:ValidationAttributes.cs

示例4: GetUserByUsername

        public static XsUser GetUserByUsername(String ntUsername)
        {
            XsUser user = null;
            if (!String.IsNullOrEmpty(ntUsername.Trim()))
            {
                IXsUserRepository userRepository = new UserRepository();
                user = userRepository.GetByUsername(ntUsername);

                if (null == user)
                {
                    user = new XsUser();
                    user.Username = ntUsername;
                    user.DisplayName = ntUsername;
                    user = userRepository.Save(user);
                }
            }

            return user;
        }
开发者ID:XpertSquare,项目名称:XpertSquare,代码行数:19,代码来源:UserHelper.cs

示例5: TryCredentials

        // Tries to authenticate given user credentials.
        // Returns empty string on success or error message on failure.
        public static string TryCredentials(string userName, string password)
        {
            if ( string.IsNullOrEmpty(userName) )
                return "empty username";
            if ( string.IsNullOrEmpty(password))
                return "empty password";

            UserRepository userRepository = new UserRepository();
            UserModel user = userRepository.GetByUsername( userName );

            if ( user == null )
                return "wrong username";
            if ( user.ActivationCode != null )
                return "account not activated";
            if ( user.Password != password.HashMD5() )
                return "wrong password";

            // credentials successfully authenticated
            return string.Empty;
        }
开发者ID:qbajas,项目名称:PhotoHistory,代码行数:22,代码来源:UserAuthentication.cs

示例6: TestAdd

        public void TestAdd()
        {
            // Arrange
            IUserRepository repository = new UserRepository();
            User u = new User
                         {
                             Username = "test",
                             Password = "Test123",
                             Firstname = "Hans",
                             Lastname = "Muster",
                             EMail = "[email protected]"
                         };

            // Act
            repository.SaveOrUpdate(u);

            // Assert
            User user = repository.GetByUsername(u.Username);
            Assert.IsNotNull(user);
            Assert.AreEqual(u.Username, user.Username);
            Assert.AreEqual(u.Firstname, user.Firstname);
            Assert.AreEqual(u.Lastname, user.Lastname);
            Assert.AreEqual(u.EMail, user.EMail);
        }
开发者ID:pweibel,项目名称:DinX,代码行数:24,代码来源:UserRepositoryTest.cs

示例7: ResetPassword

        public ActionResult ResetPassword(ResetUserPasswordModel changePassword)
        {
            if ( ModelState.IsValid )
            {
                UserRepository users = new UserRepository();
                UserModel user = users.GetByUsername( changePassword.Username );

                if ( user != null && user.ActivationCode != null && user.ActivationCode == changePassword.Token )
                {
                    users.ChangePassword( changePassword.Username, changePassword.NewPassword );
                    users.Activate( changePassword.Username );

                    return RedirectToAction( "Index", "Home" );
                }
                else
                {
                    //ViewBag.ErrorMessage = "Invalid username/token pair.";
                    return HttpNotFound( "Invalid username/token pair." );
                }
            }

            return View( changePassword );
        }
开发者ID:qbajas,项目名称:PhotoHistory,代码行数:23,代码来源:UserController.cs

示例8: DeleteComment

        public ActionResult DeleteComment(int id)
        {
            AlbumRepository albums = new AlbumRepository();
            CommentModel comment = albums.GetComment(id, true, true);
            UserRepository users = new UserRepository();
            UserModel user = users.GetByUsername(HttpContext.User.Identity.Name);
            string[] response = new string[2];

            if (user != null)
            {
                if (comment.User.Id == user.Id || comment.Album.User.Id == user.Id) //usuwac moze wlasciciel albumu lub komentarza
                {
                    response[0] = "ok";
                    response[1] = "";
                    albums.deleteComment(comment);
                }
                else
                {
                    response[0] = "error";
                    response[1] = "You are not allowed to delete this comment.";
                }
            }
            else
            {
                response[0] = "error";
                response[1] = "You need to be logged in to delete comments";
            }

            return Json(response);
        }
开发者ID:qbajas,项目名称:PhotoHistory,代码行数:30,代码来源:AlbumController.cs

示例9: CreateAlbums

        private static void CreateAlbums()
        {
            UserRepository users = new UserRepository();
            UserModel user = users.GetByUsername("Klocu");
            AlbumRepository albums = new AlbumRepository();

            CategoryModel category=null;
            using (var session = SessionProvider.SessionFactory.OpenSession())
            {
                category=session.CreateQuery("from CategoryModel where Name =:name").SetParameter("name","People").UniqueResult<CategoryModel>();
            }

            AlbumModel album = new AlbumModel()
            {
                Category = category,
                CommentsAllow = true,
                CommentsAuth = false,
                Description = "Jak zmieniałem się w czasie",
                Name = "Moja twarz",
                Public = true,
                Rating = 0,
                User = user,
                Views = 1234
            };
            albums.Create(album);

            LinkedList<PhotoModel> list = new LinkedList<PhotoModel>();
            PhotoModel photo = new PhotoModel()
            {
                Album = album,
                Date = new DateTime(2011, 1, 1, 22, 33, 5),
                Description = "Oto ja",
                Path = "/Static/photos/photo_2012051022444645.jpg"
            };
            list.AddLast(photo);
            photo = new PhotoModel()
            {
                Album = album,
                Date = new DateTime(2011,4,30,22,33,5),
                Description = "Oto ja",
                Path = "/Static/photos/photo_2012051022450267.jpg"
            };
            list.AddLast(photo);
            photo = new PhotoModel()
            {
                Album = album,
                Date = new DateTime(2012, 2,28 , 1, 8, 59),
                Description = "Oto ja",
                Path = "/Static/photos/photo_2012051022452109.jpg"
            };
            list.AddLast(photo);
            photo = new PhotoModel()
            {
                Album = album,
                Date = new DateTime(2011, 1, 8, 1, 8, 59),
                Description = "Oto ja",
                Path = "/Static/photos/20110108.jpg"
            };
            list.AddLast(photo);
            photo = new PhotoModel()
            {
                Album = album,
                Date = new DateTime(2011, 1, 15, 1, 8, 59),
                Description = "Oto ja",
                Path = "/Static/photos/20110115.jpg"
            };
            list.AddLast(photo);
            photo = new PhotoModel()
            {
                Album = album,
                Date = new DateTime(2011, 1, 22, 1, 8, 59),
                Description = "Oto ja",
                Path = "/Static/photos/20110122.jpg"
            };
            list.AddLast(photo);
            photo = new PhotoModel()
            {
                Album = album,
                Date = new DateTime(2011, 1, 29, 1, 8, 59),
                Description = "Oto ja",
                Path = "/Static/photos/20110129.jpg"
            };
            list.AddLast(photo);

            album = new AlbumModel()
            {
                Category = category,
                CommentsAllow = true,
                CommentsAuth = false,
                Description = "",
                Name = "Widok za moin oknem",
                Public = true,
                Rating = 0,
                User = user,
                Views = 2
            };
            albums.Create(album);
            photo = new PhotoModel()
            {
                Album = album,
//.........这里部分代码省略.........
开发者ID:qbajas,项目名称:PhotoHistory,代码行数:101,代码来源:BuildInitializer.cs

示例10: Edit

        public ActionResult Edit()
        {
            UserRepository users = new UserRepository();
            UserModel user = users.GetByUsername( HttpContext.User.Identity.Name );

            UserSettingsModel settings = new UserSettingsModel
            {
                DateOfBirth = user.DateOfBirth,
                About = user.About,
                NotifyComment = user.NotifyComment,
                NotifyPhoto = user.NotifyPhoto,
                NotifySubscription = user.NotifySubscription
            };

            return View( settings );
        }
开发者ID:qbajas,项目名称:PhotoHistory,代码行数:16,代码来源:UserController.cs

示例11: Subscribe

 public ActionResult Subscribe(int albumId, bool unsubscribe)
 {
     AlbumRepository albums = new AlbumRepository();
     AlbumModel album = albums.GetById(albumId, withFollowers: true);
     UserRepository users = new UserRepository();
     UserModel user = users.GetByUsername(HttpContext.User.Identity.Name);
     string[] response = new string[2];
     // reponse[0] is an operation code
     // response[1] is a message for a user
     if (user != null)
     {
         //subscribe if the user is logged in
         albums.Subscribe(album, user, unsubscribe);
         if (unsubscribe)
         {
             response[0] = "unsubscribed";
             response[1] = "You stopped following this album";
         }
         else
         {
             response[0] = "subscribed";
             response[1] = "You are now following this album";
         }
     }
     else
     {
         response[0] = "error"; //error
         response[1] = "You need to be logged in to vote";
     }
     return Json(response);
 }
开发者ID:qbajas,项目名称:PhotoHistory,代码行数:31,代码来源:AlbumController.cs

示例12: Vote

 public ActionResult Vote(int id, bool up)
 {
     AlbumRepository albums = new AlbumRepository();
     AlbumModel album = albums.GetById(id);
     UserRepository users = new UserRepository();
     UserModel user = users.GetByUsername(HttpContext.User.Identity.Name);
     string[] response = new string[2];
     // reponse[0] is a new rating
     // response[1] is a message for a user
     if (user != null)
     {
         //create vote if the user is logged in
         if (album.CreateVote(user, up))
             response[1] = "Your vote has been saved.";
         else
             response[1] = "You have already voted on this album !";
     }
     else
     {
         response[1] = "You need to be logged in to vote";
     }
     response[0] = album.getRating().ToString();
     return Json(response);
 }
开发者ID:qbajas,项目名称:PhotoHistory,代码行数:24,代码来源:AlbumController.cs

示例13: ManageAlbum

        public ActionResult ManageAlbum(int id)
        {
            AlbumRepository albums = new AlbumRepository();
            AlbumModel album = albums.GetByIdForManage(id);
            UserRepository users = new UserRepository();
            var user = users.GetByUsername(HttpContext.User.Identity.Name);

            //access control
            if (!albums.isUserAuthorizedToEditAlbum(album, user))
                return View("NotAuthorizedEdit");

            return View(album);
        }
开发者ID:qbajas,项目名称:PhotoHistory,代码行数:13,代码来源:AlbumController.cs

示例14: Show

        public ActionResult Show(int id)
        {
            AlbumRepository albums = new AlbumRepository();
            AlbumModel album = albums.GetByIdForShow(id);

            UserRepository users = new UserRepository();
            var user = users.GetByUsername(HttpContext.User.Identity.Name);

            // check if album has a password, if it does, authorize
            if (!albums.authorizeWithPassword(album, user, (string)Session["Album" + album.Id.ToString()]))
                return RedirectToAction("PasswordForAlbum", new { id = album.Id });

            // if user is not authorized
            if (!albums.IsUserAuthorizedToViewAlbum(album, user, true))
                return View("NotAuthorized");

            if (user == null || user.Id != album.User.Id) //if not logged in or not an author
            {
                //increment views
                album.Views += 1;
                albums.Update(album);
            }
            @ViewBag.user = user;
            return View(album);
        }
开发者ID:qbajas,项目名称:PhotoHistory,代码行数:25,代码来源:AlbumController.cs

示例15: RestorePassword

        public ActionResult RestorePassword(RestoreUserPasswordModel restorePassword)
        {
            if ( ModelState.IsValid )
            {
                UserRepository users = new UserRepository();
                UserModel user = (users.GetByUsername( restorePassword.Account ) ?? users.GetByEmail( restorePassword.Account ));
                if ( user == null )
                {
                    throw new Exception( string.Format(
                        "Username or e-mail address '{0}' not found - it should be already validated!", restorePassword.Account ) );
                }

                string activationCode = (new Random().Next( 1000 )).ToString().HashMD5();
                users.SetActivationCode( user.Login, activationCode );

                Uri requestUrl = Url.RequestContext.HttpContext.Request.Url;
                string activationLink = string.Format( "{0}://{1}{2}", requestUrl.Scheme, requestUrl.Authority,
                    Url.Action( "ResetPassword", "User", new { user = Url.Encode( user.Login ), token = activationCode } ) );

                try
                {
                    Helpers.SendEmail( user.Email, "PastExplorer password recovery",
                        string.Format( "Hello, click <a href=\"{0}\">here</a> to change your PastExplorer account password.", activationLink ) );
                }
                catch ( Exception )
                {
                    ViewBag.ErrorMessage = "Failed to send password recovery e-mail message. Please try again later.";
                    return View( restorePassword );
                }

                return RedirectToAction( "Index", "Home" );
            }

            return View( restorePassword );
        }
开发者ID:qbajas,项目名称:PhotoHistory,代码行数:35,代码来源:UserController.cs


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