protected void btnRegister_Click()
        {
            //Insert Emp
            String   IdEmp = "Emp-" + DateTime.Now.ToString("HH:mm:ss:ffffff");
            Employee Emp   = new Employee();

            Emp.ID_Emp   = IdEmp;
            Emp.Email    = Email.Text.ToString();
            Emp.FullName = FullName.Text.ToString();
            Emp.Phone    = Phone.Text.ToString();
            db.Employees.InsertOnSubmit(Emp);
            db.SubmitChanges();

            //Insert Account
            AccountEmp Acc   = new AccountEmp();
            String     IdAcc = "Acc-" + DateTime.Now.ToString("HH:mm:ss:ffffff");
            // Random Pass
            Random        random     = new Random();
            string        characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
            StringBuilder passRandom = new StringBuilder(8);

            for (int i = 0; i < 8; i++)
            {
                passRandom.Append(characters[random.Next(characters.Length)]);
            }
            Acc.Active     = true;
            Acc.Username   = Username.Text;
            Acc.ID_Emp     = IdEmp;
            Acc.ID_Account = IdAcc;
            Acc.Password   = HashPass.GetPass(Convert.ToString(passRandom));
            Acc.Password   = HashPass.GetPass(Convert.ToString(passRandom));
            db.AccountEmps.InsertOnSubmit(Acc);
            db.SubmitChanges();

            //Insert Roles
            Role role = new Role();

            role.ID_Account         = IdAcc;
            role.Username           = Username.Text;
            role.Role_Register      = 0;
            role.Role_Product       = 0;
            role.Roles_Manufacturer = 0;
            role.Role_Roles         = false;
            db.Roles.InsertOnSubmit(role);
            db.SubmitChanges();

            //Send Email
            MailMessage mail = new MailMessage
                                   ("*****@*****.**", Email.Text, "Account Login Page Admin", "Username: "******" Password: "******"smtp.gmail.com", 587);

            smtpClient.EnableSsl   = true;
            smtpClient.Credentials = new System.Net.NetworkCredential
                                         ("*****@*****.**", "KKkk0902");
            smtpClient.Send(mail);
            Response.Redirect("RegisterPage.aspx");
        }
Exemplo n.º 2
0
        protected void btnChangePass_Click()
        {
            AccountEmp accountEmp = db.AccountEmps.SingleOrDefault
                                        (p => p.Username == Request.Cookies["Username"].Value);

            accountEmp.Password = HashPass.GetPass(NewPassword.Text);
            db.SubmitChanges();

            Response.Cookies["Username"].Expires = DateTime.Now.AddDays(-1);
            Response.Redirect("LoginAdmin.aspx");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int UserAdmin =
                (from p in db.AccountEmps
                 where p.Username == "admin"
                 select p).Count();

            if (UserAdmin.Equals(0))
            {
                //Insert Emp
                String   IdEmp = "Emp-" + DateTime.Now.ToString("HH:mm:ss:ffffff");
                Employee Emp   = new Employee();
                Emp.ID_Emp   = IdEmp;
                Emp.Address  = "admin";
                Emp.Birthday = Convert.ToDateTime("2019-01-01");
                Emp.Email    = "*****@*****.**";
                Emp.FullName = "Admin";
                Emp.Passport = "Admin";
                Emp.Phone    = "Admin";
                Emp.Sex      = true;
                db.Employees.InsertOnSubmit(Emp);
                db.SubmitChanges();
                //Insert Account
                AccountEmp Acc   = new AccountEmp();
                String     IdAcc = "Acc-" + DateTime.Now.ToString("HH:mm:ss:ffffff");
                Acc.Active          = true;
                Acc.Username        = "******";
                Acc.Password        = HashPass.GetPass("admin");
                Acc.ID_Emp          = IdEmp;
                Acc.ID_Account      = IdAcc;
                Acc.Secret_Question = "What is the first phone number you use?";
                Acc.Secret_Answer   = "admin";
                db.AccountEmps.InsertOnSubmit(Acc);
                db.SubmitChanges();
                //Insert Roles
                Role role = new Role();
                role.ID_Account         = IdAcc;
                role.Username           = "******";
                role.Role_Register      = 15;
                role.Role_Product       = 15;
                role.Role_Roles         = true;
                role.Roles_Manufacturer = 15;
                db.Roles.InsertOnSubmit(role);
                db.SubmitChanges();
            }
        }