示例#1
0
        public TideResponse CreateAccount(string publicKey, string username, bool seed = false)
        {
            try {
                var usernameHash = username.ConvertToUint64();

                var account = $"tide{Helpers.RandomString(8)}";
                var result  = _eos.CreateTransaction(new Transaction {
                    Actions = new List <Action> {
                        new Action {
                            Account       = _settings.Onboarding,
                            Authorization = new List <PermissionLevel> {
                                new PermissionLevel {
                                    Actor = _settings.Account, Permission = "active"
                                }
                            },
                            Name = "adduser",
                            Data = new {
                                account,
                                username = usernameHash
                            }
                        }
                    }
                }).Result;

                _logger.LogMsg("Created user account");
                return(new TideResponse(true, account, null));
            }
            catch (Exception e) {
                _logger.LogMsg("Failed creating user account", ex: e);
                return(new TideResponse(false, e, "Failed creating user account."));
            }
        }
示例#2
0
        public TideResponse GetUserNodes(AuthenticationModel model)
        {
            try {
                var usernameHash = model.Username.ConvertToUint64();

                // Fetch the item from the cache, otherwise get it from the blockchain
                if (!_memoryCache.GetCacheObject(CacheKeys.TideUser, out TideUser user, usernameHash))
                {
                    user = GetTableRow <TideUser>(_settings.Onboarding, _settings.UsersTable, usernameHash);
                    if (user != null)
                    {
                        _memoryCache.SetCacheObject(CacheKeys.TideUser, user);
                    }
                }

                if (user == null)
                {
                    _logger.LogMsg("Invalid user gathering nodes", model);
                    return(new TideResponse(false, null, "Failed gathering nodes"));
                }

                _logger.LogMsg("Gathered nodes", model);
                return(new TideResponse(true, user.Nodes, null));
            }
            catch (Exception e) {
                _logger.LogMsg("Error gathering nodes", model, e);
                return(new TideResponse(false, null, "Unable to gather nodes"));
            }
        }
        public AuthenticationRequest GenerateToken(AuthenticationRequest request)
        {
            var user = FetchUser(request.User.Username);

            if (user == null)
            {
                _logger.LogMsg("Incorrect username attempt", new AuthenticationModel {
                    Username = request.User.Username, Ip = request.Ip
                });
                return(null);
            }

            // Encrypt the token with the end users public key. If they're able to decrypt it we know they're valid
            request.Token = Cryptide.Instance.Encrypt(GenerateToken(request.User.Username), user.VendorPublicKey);

            _logger.LogMsg("Created token for user", new AuthenticationModel {
                Username = request.User.Username, Ip = request.Ip
            });
            return(request);
        }
示例#4
0
        public TideResponse GetUserNodes(AuthenticationModel model)
        {
            try {
                var usernameHash = model.Username.ConvertToUint64();

                // Fetch the item from the cache, otherwise get it from the blockchain
                var user = _repo.GetUser(usernameHash);

                if (user == null)
                {
                    _logger.LogMsg("Invalid user gathering nodes", model);
                    return(new TideResponse(false, null, "Failed gathering nodes"));
                }

                _logger.LogMsg("Gathered nodes", model);
                return(new TideResponse(true, user.Nodes, null));
            }
            catch (Exception e) {
                _logger.LogMsg("Error gathering nodes", model, e);
                return(new TideResponse(false, null, "Unable to gather nodes"));
            }
        }