public IActionResult Create(Company company)
        {
            if (!ModelState.IsValid)
            {
                ViewData["Message"] = "Invalid Input";
                ViewData["MsgType"] = "warning";
                return(View("Create"));
            }

            else
            {
                string insert  = @"INSERT INTO Email(Email, EmailStatus) VALUES('{0}',0)";
                string insert1 = @"INSERT INTO AppUser(UserName, User_PW, RepName, Contact_Num, CompanyName, CompanyWebsite, CompanyIndustry, CompanySize, CompanyType, Email) VALUES('{0}', HASHBYTES('SHA1', '{1}'), '{2}', {3}, '{4}', '{5}', '{6}', '{7}', 2, '{8}')";

                int result  = DBUtl.ExecSQL(insert, company.Email);
                int result1 = DBUtl.ExecSQL(insert1, company.UserName, company.User_PW, company.RepName, company.Contact_Num, company.CompanyName, company.CompanyWebsite, company.CompanyIndustry, company.CompanySize, company.Email);


                if (result == 1 && result1 == 1)
                {
                    TempData["Mesage"]  = "Account Created";
                    TempData["MsgType"] = "success";

                    string    email  = company.Email.ToString();
                    string    select = "SELECT * FROM AppUser WHERE Email='{0}'";
                    DataTable dt     = DBUtl.GetTable(select, email);

                    foreach (DataRow row in dt.Rows)
                    {
                        string RepName  = row.Field <string>("RepName");
                        string Email    = row.Field <string>("Email");
                        string UserName = row.Field <string>("UserName");

                        string template = @"Hi {0}, <br></br> Welcome to Tribe Accelerator! Your username is {1}. To activate your account, click here <button><a href='" + Url.Action("Activate", "Company", new { un = Email }, "http") + "'>Activate</a></button><br></br>" + "Regards,<br></br> The Tribe Accelerator team";
                        string title    = "Account Activation";
                        string message  = string.Format(template, RepName, UserName);
                        string rs;
                        if (EmailUtl.SendEmail(email, title, message, out rs))
                        {
                            ViewData["Message"] = "Email successfully sent";
                            ViewData["MsgType"] = "success";
                        }
                        else
                        {
                            ViewData["Message"] = result;
                            ViewData["MsgType"] = "warning";
                        }
                        return(View("Confirmation"));
                    }
                }
                else
                {
                    TempData["Message"] = DBUtl.DB_Message;
                    TempData["MsgType"] = "danger";
                }
                return(Redirect("~/Home/Index"));
            }
        }
Пример #2
0
        public IActionResult Create(User newUser)
        {
            if (!ModelState.IsValid)
            {
                ViewData["Message"] = "Invalid Input";
                ViewData["MsgType"] = "warning";
                return(View("Create"));
            }
            else
            {
                string insert =
                    @"INSERT INTO Users(Username, FullName, Email, Password, UserRole, CompanyName, ContactNo) 
                VALUES('{0}', '{1}', '{2}', HASHBYTES('SHA1', '{3}'), '{4}', '{5}', '{6}')";

                int result = DBUtl.ExecSQL(insert, newUser.Username, newUser.FullName, newUser.Email, newUser.Password, newUser.UserRole, newUser.CompanyName, newUser.ContactNo);

                if (result == 1)
                {
                    TempData["Message"] = "User Created";
                    TempData["MsgType"] = "success";
                    string    email  = newUser.Email.ToString();
                    string    select = "SELECT * FROM Users WHERE Email='{0}'";
                    DataTable dt     = DBUtl.GetTable(select, email);
                    foreach (DataRow row in dt.Rows)
                    {
                        string fullname = row.Field <string>("FullName");
                        string Email    = row.Field <string>("Email");
                        string template = @"Hi {0}, <br></br>
                                            Please press this link to activate your Accelerator Account. <br></br>
                                            <button><a href='" + Url.Action("Activation", "Account", new { un = fullname }, "http") + "'>Activate</a></button><br></br>" + "Cheers, <br></br>" + "<i>Accelerator</i>";
                        string title    = "Activating Accelerator Account";
                        string message  = String.Format(template, fullname);
                        string rs;
                        if (EmailUtl.SendEmail(email, title, message, out rs))
                        {
                            ViewData["Message"] = "Email Successfully Sent";
                            ViewData["MsgType"] = "success";
                        }
                        else
                        {
                            ViewData["Message"] = result;
                            ViewData["MsgType"] = "warning";
                        }
                        return(View("Activate"));
                    }
                }
                else
                {
                    TempData["Message"] = DBUtl.DB_Message;
                    TempData["MsgType"] = "danger";
                }
                return(RedirectToAction("ListUsers"));
            }
        }
Пример #3
0
        public IActionResult Register(UserRegister usr)
        {
            if (!ModelState.IsValid)
            {
                ViewData["Message"] = "Invalid Input";
                ViewData["MsgType"] = "warning";
                return(View("Register"));
            }
            else
            {
                IFormCollection form  = HttpContext.Request.Form;
                string          refer = form["Region"].ToString().Trim();

                string insert =
                    @"INSERT INTO UserRegister(UserId, UserPw, FirstName, LastName, Email, ContactNo, StreetAddress, UnitNo, Postal, Region, UserRole) VALUES
                  ('{0}', HASHBYTES('SHA1', '{1}'), '{2}', '{3}','{4}','{5}','{6}','{7}', '{8}', '{9}', 'member' )";
                if (DBUtl.ExecSQL(insert, usr.UserId, usr.UserPw, usr.FirstName, usr.LastName, usr.Email, usr.ContactNo, usr.StreetAddress, usr.UnitNo, usr.Postal, usr.Region, usr.UserRole) == 1)
                {
                    string template = @"<h2> Hi {0}, </h2><br/>
                                <h1 style='color:red;'> Welcome to FIRE & GAS SENSOR FOR RESIDENTIAL PROPERTIES </h1>
                                <h3 style='color:blue;'> 🔥 PROJECT ID: SOI-2020-2010-0033 🔥 </h3><br/> 
                                Your User ID is <b style='background-color:yellow;'> {1} </b>  and Password is <b style='background-color:yellow;'> {2} </b>.
                                <br><br/>Member";

                    string title   = "Registration Successul - Welcome";
                    string message = String.Format(template, usr.FirstName, usr.UserId, usr.UserPw);
                    string result;


                    if (EmailUtl.SendEmail(usr.Email, title, message, out result))
                    {
                        ViewData["Message"] = "User Successfully Registered";
                        ViewData["MsgType"] = "success";
                        return(View("UserLogin"));
                    }


                    else
                    {
                        ViewData["Message"] = result;
                        ViewData["MsgType"] = "warning";
                    }
                }
                else
                {
                    ViewData["Message"] = "User ID already exist";
                    ViewData["MsgType"] = "danger";
                    return(View("Register"));
                }
                return(View("Register"));
            }
        }
Пример #4
0
        public IActionResult Register(User usr)
        {
            if (!ModelState.IsValid)
            {
                ViewData["Message"] = "Invalid Input";
                ViewData["MsgType"] = "warning";
                return(View("RegisterUser"));
            }
            else
            {
                string insert = @"INSERT INTO User(Username, Password, FullName, Email, UserRole) VALUES('{0}', HASHBYTES('SHA1', '{1}', '{2}', '{3}', 'Startup')";
                if (DBUtl.ExecSQL(insert, usr.Username, usr.Password, usr.FullName, usr.Email) == 1)
                {
                    string template = @"Hi {0}, <br/><br/>
                                      Welcome to StartUp Accelerator!
                                      Your username is <b>{1}</b> and password is <b>{2}</b>.
                                      <br/><br/>Admin";
                    string title    = "Registration Successful - Welcome";
                    string message  = String.Format(template, usr.FullName, usr.Username, usr.Password);
                    string result   = "";

                    bool outcome = false;

                    outcome = EmailUtl.SendEmail(usr.Email, title, message, out result);

                    if (outcome)
                    {
                        ViewData["Message"] = "User Successfully Registered";
                        ViewData["MsgType"] = "success";
                    }
                    else
                    {
                        ViewData["Message"] = result;
                        ViewData["MsgType"] = "warning";
                    }
                }
                else
                {
                    ViewData["Message"] = DBUtl.DB_Message;
                    ViewData["MsgType"] = "danger";
                }
                return(View("RegisterUser"));
            }
        }
Пример #5
0
        public IActionResult ForgotPwd(ForgotPwd forgotPwd)
        {
            string    email  = forgotPwd.Email.ToString();
            string    select = "SELECT * FROM Users WHERE Email='{0}'";
            DataTable dt     = DBUtl.GetTable(select, email);

            foreach (DataRow row in dt.Rows)
            {
                string fname = row.Field <string>("FullName");
                string Email = row.Field <string>("Email");

                string template = @"Hi {0}, <br></br>
                                  We received a request to reset your password for your Accelerator Account. We're here to help!<br></br>
                                   Simply click on the button to set a new password:<br></br>
                                   <button><a href='" + Url.Action("ResetPassword", "Account", new { un = fname }, "http") + "'>Set a New Password</a></button><br></br>" +
                                  "If you didn't ask to change your password, don't worry! Your password is still safe and you can delete this email.<br></br>" +
                                  "Cheers,<br></br>" +
                                  "<i>Accelerator</i>";
                string title   = "Reset Password";
                string message = String.Format(template, fname);
                string result;

                if (EmailUtl.SendEmail(email, title, message, out result))
                {
                    ViewData["Message"] = "Email Successfully Sent";
                    ViewData["MsgType"] = "success";
                }
                else
                {
                    ViewData["Message"] = result;
                    ViewData["MsgType"] = "warning";
                }

                return(View("ForgotPwdCfm"));
            }

            //Create necessary database to store user info if required
            // To code for forgot password to send user email for the password reset link //


            return(View()); //TO remove or edit this line of code//
        }
Пример #6
0
        public IActionResult ResetPWEmail(ResetPWEmail Reset)
        {
            var output = VerifyEmail(Reset.Email);

            if (output == true)
            {
                string    email  = Reset.Email.ToString();
                string    select = "SELECT * FROM AppUser WHERE Email='{0}'";
                DataTable dt     = DBUtl.GetTable(select, email);

                foreach (DataRow row in dt.Rows)
                {
                    string Username = row.Field <string>("UserName");
                    string Email    = row.Field <string>("Email");

                    string template = @"Hi {0}, <br></br> To reset your password, click the link here : <br></br><a href='" + Url.Action("ResetPW", "Account", new { un = Username }, "http") + "'>Set your new password</a></button><br></br>" + "If you did not a request a password change, you can delete this email.<br></br>" + "Regards,<br></br>" + "<i>Tribe Accelerator</i>";

                    string title   = "Password Change";
                    string message = String.Format(template, Username);

                    if (EmailUtl.SendEmail(email, title, message, out string result))
                    {
                        ViewData["Message"] = "Email Successfully Sent";
                        ViewData["MsgType"] = "success";
                        return(View("ResetPWConfirm"));
                    }

                    else
                    {
                        ViewData["Message"] = result;
                        ViewData["MsgType"] = "warning";
                    }
                }
            }
            else
            {
                ViewData["Message"] = "No such email exists.";
                ViewData["MsgType"] = "warning";
                return(View("ResetPWEmail"));
            }
            return(View());
        }
        public IActionResult Register(TSHUsers usr)
        {
            if (!ModelState.IsValid)
            {
                ViewData["Message"] = "Invalid Input";
                ViewData["MsgType"] = "warning";
                return(View("UserRegister"));
            }
            else
            {
                string insert =
                    @"INSERT INTO TSHUsers(UserId, UserPw, FullName, Email, UserRole) 
                        VALUES('{0}', HASHBYTES('SHA1','{1}'), '{2}', '{3}', 'member')";
                if (DBUtl.ExecSQL(insert, usr.UserId, usr.UserPw, usr.FullName, usr.Email) == 1)
                {
                    string template = @"Hi {0},<br/><br/>
                               Welcome to TSH!
                               Your userid is <b>{1}</b> and password is <b>{2}</b>.
                               <br/><br/>Manager";
                    string title    = "Registration Successul - Welcome";
                    string message  = String.Format(template, usr.FullName, usr.UserId, usr.UserPw);
                    string result;

                    if (EmailUtl.SendEmail(usr.Email, title, message, out result))
                    {
                        ViewData["Message"] = "User Successfully Registered";
                        ViewData["MsgType"] = "success";
                    }
                    else
                    {
                        ViewData["Message"] = result;
                        ViewData["MsgType"] = "warning";
                    }
                }
                return(View("UserRegister"));
            }
        }
Пример #8
0
        public ObjectResult Post([FromForm] WebAPIEvent apiEvent)
        {
            var newEvent = (SchedulerEvent)apiEvent;

            _context.Event.Add(newEvent);
            _context.SaveChanges();

            var ev = _context.Event.Find(newEvent.Id);

            if ((ev.Id == newEvent.Id) && (newEvent.Type == "Startup"))
            {
                string    select = "SELECT * FROM Users WHERE UserRole='Startup'";
                DataTable dt     = DBUtl.GetTable(select);

                foreach (DataRow row in dt.Rows)
                {
                    string fname    = row.Field <string>("FullName");
                    string email    = row.Field <string>("Email");
                    string template = @"Hi {0},<br/><br/>
                               You are invited to the event - <b>{1}</b><br/><br/>
                               Start Date and Time  : <b>{2}</b><br/><br/>
                               End Date and Time    : <b>{3}</b><br/><br/>";
                    string title    = "Invitation to Attend Program";
                    string message  = String.Format(template, fname, newEvent.Title, newEvent.StartDate, newEvent.EndDate);
                    string result;
                    EmailUtl.SendEmail(email, title, message, out result);
                }
            }
            else if ((ev.Id == newEvent.Id) && (newEvent.Type == "Alumni"))
            {
                string    select = "SELECT * FROM Users WHERE UserRole='Alumni'";
                DataTable dt     = DBUtl.GetTable(select);

                foreach (DataRow row in dt.Rows)
                {
                    string fname    = row.Field <string>("FullName");
                    string email    = row.Field <string>("Email");
                    string template = @"Hi {0},<br/><br/>
                               You are invited to the event - <b>{1}</b><br/><br/>
                               Start Date and Time  : <b>{2}</b><br/><br/>
                               End Date and Time    : <b>{3}</b><br/><br/>
                               Venue                : <b>{4}</b>";
                    string title    = "Invitation to Attend Program";
                    string message  = String.Format(template, fname, newEvent.Title, newEvent.StartDate, newEvent.EndDate, newEvent.Venue);
                    string result;
                    EmailUtl.SendEmail(email, title, message, out result);
                }
            }
            else if ((ev.Id == newEvent.Id) && (newEvent.Type == "Both"))
            {
                string    select = "SELECT * FROM Users WHERE UserRole='Startup' AND UserRole='Alumni'";
                DataTable dt     = DBUtl.GetTable(select);

                foreach (DataRow row in dt.Rows)
                {
                    string fname    = row.Field <string>("FullName");
                    string email    = row.Field <string>("Email");
                    string template = @"Hi {0},<br/><br/>
                               You are invited to the event - <b>{1}</b><br/><br/>
                               Start Date and Time  : <b>{2}</b><br/><br/>
                               End Date and Time    : <b>{3}</b><br/><br/>";
                    string title    = "Invitation to Attend Program";
                    string message  = String.Format(template, fname, newEvent.Title, newEvent.StartDate, newEvent.EndDate);
                    string result;
                    EmailUtl.SendEmail(email, title, message, out result);
                }
            }

            // delete a single occurrence from a recurring series
            var resultAction = "inserted";

            if (newEvent.RecType == "none")
            {
                resultAction = "deleted";
            }

            return(Ok(new
            {
                tid = newEvent.Id,
                action = resultAction
            }));
        }