Exemple #1
0
        private void Register(NHibernate.ISession session, string username, string password, string email)
        {
            Log.Info("HIT REGISTER FUNCTION");

            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password) ||
                string.IsNullOrWhiteSpace(email))
            {
                SendError("All Fields Are required!");
                return;
            }

            if (username.Length > 128)
            {
                SendError("Username must be less than 128 characters!");
                return;
            }

            if (email.Length > 200)
            {
                SendError("Email must be less than 200 characters!");
                return;
            }

            if (session.Query <User>().Any(t => t.Username == username || t.Email == email))
            {
                SendError("Username and email must be unique!");
                return;
            }

            var user = new User
            {
                Email     = email,
                CreatedAt = DateTime.UtcNow,
                Username  = username,
                Password  = HashedPassword.FromPlainText(password)
            };

            session.Save(user);
            SendSuccess();
        }