public async Task <IActionResult> Create(Feedback feedback)
        {
            if (feedback.FeedbackText == null)
            {
                return(RedirectToAction("New", new { uid = feedback.UserID }));
            }
            _context.Add(feedback);
            _context.SaveChanges();

            // trigger email with unique feedback link and message
            var user = _context.Users.Find(feedback.UserID);

            using (var client = new HttpClient())
            {
                var values = new Dictionary <string, string>
                {
                    { "email", user.Email },
                    { "feedback_text", feedback.FeedbackText },
                    { "first_name", user.FullName.Split(' ')[0] }
                };

                string output = JsonConvert.SerializeObject(values);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var response = await client.PostAsync("https://prod-12.westus.logic.azure.com:443/workflows/bf84617c86174fbebc78e9fecc99f21f/triggers/request/run?api-version=2016-06-01&sp=%2Ftriggers%2Frequest%2Frun&sv=1.0&sig=OVO2EJShxToD-1BgkAa7r6idmcUJbgCnNK4wAsf-GvQ", new StringContent(output, Encoding.UTF8, "application/json"));

                var responseString = await response.Content.ReadAsStringAsync();
            }

            return(RedirectToAction("New", "Users"));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(User user)
        {
            //Should add unqiueness constraint on email
            //Should lowercase email before saving

            //commenting out password since this is being removed.
            //There currently isn't a reason for registered users to login
            // generate a 128-bit salt using a secure PRNG

            /*byte[] salt = new byte[128 / 8];
             * using (var rng = RandomNumberGenerator.Create())
             * {
             *  rng.GetBytes(salt);
             * }
             *
             * // derive a 256-bit subkey (use HMACSHA1 with 10,000 iterations)
             * string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
             *  password: user.Password,
             *  salt: salt,
             *  prf: KeyDerivationPrf.HMACSHA1,
             *  iterationCount: 10000,
             *  numBytesRequested: 256 / 8));
             *
             * user.PasswordHashed = hashed;
             * user.PasswordSalt = salt;
             * user.Password = "";
             * user.PasswordConfirmed = "";*/
            if (user.Email == null || user.FullName == null)
            {
                return(RedirectToAction("New"));
            }
            user.ID = Guid.NewGuid();
            _context.Add(user);
            _context.SaveChanges();

            // trigger email with unique feedback link and message
            using (var client = new HttpClient())
            {
                var values = new Dictionary <string, string>
                {
                    { "email", user.Email },
                    { "feedback_link", "http://smartfeedback.azurewebsites.net/Feedbacks/New?uid=" + user.ID.ToString() },
                    { "first_name", user.FullName.Split(' ')[0] }
                };

                string output = JsonConvert.SerializeObject(values);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var response = await client.PostAsync("https://prod-23.westus2.logic.azure.com:443/workflows/20f19b0072834a63a0f1ed8aa7316944/triggers/request/run?api-version=2016-06-01&sp=%2Ftriggers%2Frequest%2Frun&sv=1.0&sig=wYCQdY1g8RpFu8GEWcz8W_KyPc1-a530BolouqqwAK8", new StringContent(output, Encoding.UTF8, "application/json"));

                var responseString = await response.Content.ReadAsStringAsync();
            }

            return(RedirectToAction("New"));
        }