Esempio n. 1
0
        public async Task <string> Create(NewAccountInfo newAccountInfo)
        {
            await DatabaseFunctions.InitializeStaticStorage(_db).ConfigureAwait(false);

            if (newAccountInfo is null)
            {
                return("No credentials received");
            }

            newAccountInfo.CredentialsUsername = newAccountInfo.CredentialsUsername.ToLower();
            // checks if the email is legit or not
            if (!EmailServices.VerifyEmail(newAccountInfo.CredentialsUsername))
            {
                return("Invalid email");
            }

            var credentialList = await DatabaseFunctions.GetCredentials(_db, newAccountInfo).ConfigureAwait(false);

            if (credentialList.Count != 0)
            {
                return("Email already exists");
            }

            var pcCredentialPassword = await DatabaseFunctions.CreateNewCredentials(_db, newAccountInfo).ConfigureAwait(false);

            await DatabaseFunctions.CreateNewAdmin(_db, newAccountInfo).ConfigureAwait(false);

            StaticStorageServices.PcMapper.Add(newAccountInfo.CredentialsUsername, new Dictionary <string, DiagnosticData>());

            //send pcCredential password to the new user
            await EmailServices.SendEmail(newAccountInfo.CredentialsUsername, $"Pc Credential Password: {pcCredentialPassword}");

            return("Success");
        }