Example #1
0
        public Tuple <bool, Guid?> RegisterUser(JournalUserIdentity user)
        {
            if (new List <JournalUserIdentity>(users.Values).Exists(u =>
                                                                    String.Equals(u.UserName, user.UserName, StringComparison.CurrentCultureIgnoreCase) ||
                                                                    String.Equals(u.Email, user.Email, StringComparison.CurrentCultureIgnoreCase)))
            {
                return(new Tuple <bool, Guid?> (false, null));
            }
            user.Password = user.Password.BCrypt();
            var guid = Guid.NewGuid();

            users.Add(guid, user);
            return(new Tuple <bool, Guid?> (true, guid));
        }
        public Tuple <bool, Guid?> RegisterUser(JournalUserIdentity user)
        {
            var transaction = GetTransaction();

            var existingSql = "select * from users where username=:username or email=:email;";

            var existing = transaction.Connection
                           .Query(
                existingSql,
                new { username = user.UserName, email = user.Email },
                transaction.Instance)
                           .FirstOrDefault();

            if (existing != null)
            {
                return(new Tuple <bool, Guid?> (false, null));
            }

            var insertSql         = @"
				insert into users (id, username, name, email, password)
				values (:id, :username, :name, :email, :password);
				"                ;
            var id                = Guid.NewGuid();
            var encryptedPassword = user.Password.BCrypt();
            var result            = transaction.Connection
                                    .Execute(
                insertSql,
                new {
                id       = id,
                username = user.UserName,
                name     = user.Name,
                email    = user.Email,
                password = encryptedPassword
            },
                transaction.Instance);

            return(result > 0
                                ? new Tuple <bool, Guid?> (true, id)
                                : new Tuple <bool, Guid?> (false, null));
        }