Esempio n. 1
0
        private async Task FeedbackFormComplete(IDialogContext context, IAwaitable <FeedbackForm> result)
        {
            try
            {
                var     feedback = await result;
                Boolean success  = cbaDAO.insertFeedback(feedback.Name, feedback.Feedback, feedback.Department, DateTime.Now);
                if (!success)
                {
                    await context.PostAsync("I was not able to send your message. Something went wrong.");
                }
                else
                {
                    //to send success email
                    ChatBotFeedbackSettingsDAO cbfsDAO         = new ChatBotFeedbackSettingsDAO();
                    ChatBotFeedbackSettings    currentSettings = cbfsDAO.getCurrentSettings();
                    if (currentSettings.enabled.Equals("y"))
                    {
                        SmtpClient client = new SmtpClient("Host");
                        client.Host        = "smtp.gmail.com";
                        client.Port        = 587;
                        client.EnableSsl   = true;
                        client.Credentials = new NetworkCredential(currentSettings.smtpUsername, currentSettings.smtpPassword);
                        MailMessage mailMessage = new MailMessage();
                        mailMessage.IsBodyHtml = true;
                        mailMessage.From       = new MailAddress("*****@*****.**");
                        mailMessage.To.Add(currentSettings.emailToSendTo);
                        mailMessage.Body    = $"Hi, <br /><br /> New feedback received from {feedback.Name}, {feedback.Department}. <br /><br />His/her feedback is: <br />{feedback.Feedback}.";
                        mailMessage.Subject = "New Feedback";
                        client.Send(mailMessage);
                    }
                    await context.PostAsync("Thanks for the feedback.");

                    await context.PostAsync("What else would you like to do?");
                }
            }
            catch (FormCanceledException)
            {
                await context.PostAsync("Don't want to send feedback? Alright!");
            }
            catch (Exception e)
            {
                await context.PostAsync(e.Message);

                await context.PostAsync("Something really bad happened. You can try again later meanwhile I'll check what went wrong.");
            }
            finally
            {
                context.Wait(MessageReceived);
            }
        }
Esempio n. 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["currentUser"] != null)
            {
                User currentUser = (User)Session["currentUser"];

                Boolean superuser = false;
                foreach (String s in currentUser.getRoles())
                {
                    if (s.Equals("superuser"))
                    {
                        superuser = true;
                    }
                }
                if (!currentUser.getDepartment().Equals("hr"))
                {
                    if (!superuser)
                    {
                        Response.Redirect("errorPage.aspx");
                    }
                }
                else
                {
                    if (!IsPostBack)
                    {
                        ChatBotFeedbackSettingsDAO cbfsDAO         = new ChatBotFeedbackSettingsDAO();
                        ChatBotFeedbackSettings    currentSettings = cbfsDAO.getCurrentSettings();
                        if (currentSettings.enabled.Equals("y"))
                        {
                            rdlEmail.SelectedValue = "y";
                        }
                        else
                        {
                            rdlEmail.SelectedValue = "n";
                        }
                        txtEmail.Text        = currentSettings.emailToSendTo;
                        txtSMTPUser.Text     = currentSettings.smtpUsername;
                        txtSMTPPassword.Text = currentSettings.smtpPassword;
                        txtSMTPPassword.Attributes["type"] = "password";
                    }
                }
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }
        protected void btnRequest_Click(object sender, EventArgs e)
        {
            string  email    = txtEmail.Text;
            UserDAO udao     = new UserDAO();
            User    toChange = udao.getUserByEmail(email); //find email in database.

            //change password in db for this email to auto generated password
            if (toChange != null)
            {
                string  randompassword  = System.Web.Security.Membership.GeneratePassword(8, 1);
                string  salt            = Crypto.GenerateSalt();                                    // generate salt of user
                string  password_hashed = Crypto.SHA256(salt + randompassword);                     // generate hashed random password
                Boolean success         = udao.updateUserPassword(toChange, password_hashed, salt); // update db with new salt and password
                //send email based on chatbot configs for smtp mail server
                try
                {
                    ChatBotFeedbackSettingsDAO cbfsDAO         = new ChatBotFeedbackSettingsDAO();
                    ChatBotFeedbackSettings    currentSettings = cbfsDAO.getCurrentSettings();
                    SmtpClient client = new SmtpClient("Host");
                    client.Host        = "smtp.gmail.com";
                    client.Port        = 587;
                    client.EnableSsl   = true;
                    client.Credentials = new NetworkCredential(currentSettings.smtpUsername, currentSettings.smtpPassword);
                    MailMessage mailMessage = new MailMessage();
                    mailMessage.IsBodyHtml = true;
                    mailMessage.From       = new MailAddress("*****@*****.**");
                    mailMessage.To.Add(toChange.getEmail());
                    mailMessage.Body    = $"Hi, {toChange.getName()}<br /><br /> A password change was requested. <br /><br />The new password is: <br /><b>{randompassword}</b><br /><br />Please change your password upon login.<br /><br />You do not have to reply to this email as it's auto-generated";
                    mailMessage.Subject = "Change password";
                    client.Send(mailMessage);
                    panelSuccessMsg.Visible = true;
                }
                catch (Exception)
                {
                    panelErrorMsg.Visible = true;
                }
            }
            else
            {
                panelErrorMsg.Visible = true;
            }
        }