예제 #1
0
 private static OpenIdIdentity CreateFakeIdentity()
 {
     var userData = new Core.DataModel.User();
     var ticket = new FormsAuthenticationTicket(1, "ticket", DateTime.Now,
                                                 DateTime.Now.AddDays(1), false,
                                                 userData.ToString());
     var id = new OpenIdIdentity(ticket);
     return id;
 }
        public void UserIsInserted()
        {
            var user = new Core.DataModel.User
                {
                    EmailAddress = "*****@*****.**",
                    Id = Guid.NewGuid(),
                    OpenId = "http://faa.foo.com/08?dkkdkdkdkd"
                };

            var repo = Substitute.For<Core.DataAbstractions.IRepository<User>>();
            var hander = new InsertUserCommandHandler(repo);
            var command = new InsertUserCommand(user);
            hander.Handle(command);

            repo.Received(1).Add(Arg.Is(user));
        }
예제 #3
0
        public Core.DataModel.User CreateUser(Core.DataModel.User user, string password)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentException("Password is required");
            }

            var existUser = _userRepository.GetAll().FirstOrDefault(u => u.Email.Equals(user.Email));

            if (existUser != null)
            {
                throw new ArgumentException("Username is already exists");
            }

            CreatePasswordHash(password, out var passwordHash, out var passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            _userRepository.Insert(user);

            return(user);
        }
예제 #4
0
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);

            if (requestContext.HttpContext.Request.IsAuthenticated)
            {
                _currentUser = ((OpenIdIdentity)User.Identity).UserInfo;
            }
        }