public void AppendToQueryParameters(Dictionary <string, string> queryParameters)
        {
            if (Phased)
            {
                queryParameters.Add(Parameters.Phased, Phased.ToString());
                queryParameters.Add(Parameters.PhasingFinishHeight, FinishHeight.ToString());
                queryParameters.Add(Parameters.PhasingVotingModel, ((int)VotingModel).ToString());
                queryParameters.Add(Parameters.PhasingQuorum, Quorum.ToString());

                if (MinBalance > 0)
                {
                    queryParameters.Add(Parameters.PhasingMinBalance, MinBalance.ToString());
                }
                if (HoldingId > 0)
                {
                    queryParameters.Add(Parameters.PhasingHolding, HoldingId.ToString());
                }
                if (MinBalanceModel != MinBalanceModel.None)
                {
                    queryParameters.Add(Parameters.PhasingMinBalanceModel, ((int)MinBalanceModel).ToString());
                }
                WhiteListed.ForEach(w => queryParameters.Add(Parameters.PhasingWhitelisted, w.AccountRs));
                LinkedFullHash.ForEach(h => queryParameters.Add(Parameters.PhasingLinkedFullHash, h.ToHexString()));
                if (HashedSecret != null)
                {
                    queryParameters.Add(Parameters.PhasingHashedSecret, HashedSecret.ToHexString());
                }
                if (HashedSecretAlgorithm.HasValue)
                {
                    queryParameters.Add(Parameters.PhasingHashedSecretAlgorithm, ((int)HashedSecretAlgorithm.Value).ToString());
                }
            }
        }
Beispiel #2
0
        public User registerUser(RegisterRequest request)
        {
            if (findByUsername(request.username) != null)
            {
                throw new UserAlreadyExistsException("a user with the same username already exists");
            }
            if (findByEmail(request.email) != null)
            {
                throw new UserAlreadyExistsException("a user with the same email already exists");
            }
            // encrypt the password
            var cryptPassword = HashedSecret.withDefaultParameters();
            var cryptoHelper  = new PasswordHasher(cryptPassword);

            cryptoHelper.store(request.password);
            // create the user
            var user = new User {
                name         = request.name,
                username     = request.username,
                email        = request.email,
                uuid         = Guid.NewGuid().ToString("N"),
                password     = cryptPassword,
                pronouns     = Enum.Parse <User.Pronouns>(request.pronouns, true),
                verification = StringUtils.secureRandomString(8),
                registered   = DateTime.UtcNow,
                groups       = new string[0]
            };

            // - set default settings
            // add groups from default groups
            user.groups = serverContext.config.users.defaultGroups.ToArray();

#if DEBUG
            if (serverContext.config.server.development)
            {
                // if in development, set a default verification code
                user.verification = Constants.DEFAULT_VERIFICATION;
            }
#endif

            using (var db = serverContext.getDbContext()) {
                db.users.Add(user); // add user
                db.SaveChanges();
            }

            return(user);
        }
Beispiel #3
0
 public PasswordHasher(HashedSecret hashedSecret)
 {
     this.hashedSecret = hashedSecret;
 }