public JObject Register(JObject json) { var user = json["fields"].ToObject <User>(); json = Validate(json); if (json.ContainsKey("invalidFields")) { return(json); } user.PublicKey = CryptographyService.GetPublicKeyFromPrivate(user.PrivateKey); user.PrivateKey = null; // since the service lies on blockchain, private keys must not be stored user.Enabled = true; user.CorrespondingIndices = new Dictionary <string, string>(); // For now, the newly created user is considered to belong to the demo company created during initialization. if (user.Position.Equals("companyVesselsRegistryManager")) { user.Company = "1234567890"; } _usersDataAccess.Insert(user); json["saved"] = _usersDataAccess.FindByPublicKey(user.PublicKey) != null; if (!json["saved"].ToObject <bool>()) { return(json); } json["token"] = GenerateToken(user); return(json); }