예제 #1
0
        /// <summary>
        /// Adds a new document to the given phase.
        /// </summary>
        /// <param name="container">The container holding the document.</param>
        /// <param name="stream">The stream for the document.</param>
        /// <param name="name">The name for the document.</param>
        /// <param name="creator">The creator of the document.</param>
        public Document AddDocument(IDocumentContainer container, Stream stream, string name, User creator)
        {
            Condition.Requires(container)
               .IsNotNull();
            Condition.Requires(stream)
                .IsNotNull()
                .Evaluate(f => f.Length > 0);
            Condition.Requires(name)
                .IsNotNullOrWhiteSpace();
            Condition.Requires(creator)
                .IsNotNull();

            string attachementId = this.CreateNewAttachementId();
            this._documentSession.Advanced.DocumentStore.DatabaseCommands.PutAttachment(attachementId, null, stream, null);

            var document = new Document
            {
                CreatedByUserId = creator.Id,
                Name = name,
                AttachementId = attachementId
            };

            container.Documents.Add(document);

            return document;
        }
예제 #2
0
        /// <summary>
        /// Registers a new user with the given username and password.
        /// The username needs to be unique.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="emailAddress"></param>
        /// <exception cref="Xemio.ProjectCoach.Core.Exceptions.UsernameAlreadyExistsException"></exception>
        public User Register(string username, string password, string emailAddress)
        {
            Condition.Requires(username, "username")
                .IsNotNullOrWhiteSpace();
            Condition.Requires(password, "password")
                .IsNotNullOrWhiteSpace()
                .IsLongerOrEqual(6);
            Condition.Requires(emailAddress, "emailAddress")
                .IsNotNullOrWhiteSpace()
                .Evaluate(f => f.IsEmailAddress());

            bool usernameExists = this._documentSession.Query<User, Users_ByUsername>()
                .Any(f => f.Username == username);

            if (usernameExists)
                throw new UsernameAlreadyExistsException(username);

            var user = new User
                           {
                               Username = username,
                               EmailAddress = emailAddress
                           };

            this._documentSession.Store(user);

            byte[] salt = this._saltService.CreateSalt();
            byte[] passwordHash = this._hashService.CreateHash(password, salt);

            var authenticationData = new AuthenticationData
                                         {
                                             UserId = user.Id,
                                             Salt = salt,
                                             PasswordHash = passwordHash
                                         };

            this._documentSession.Store(authenticationData);

            return user;
        }