示例#1
0
        protected void btnUpdatePass_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(tbxNewPass.Text) && !string.IsNullOrWhiteSpace(tbxConfirmNewPass.Text))
            {
                Regex regPass = new Regex(@"^.*(?=.{8,50})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!.@#$%^&+=]).*$");

                if (tbxNewPass.Text.ToLower().Contains("user") || tbxNewPass.Text == "User.123")
                {
                    lblNewPassError.Text = "Password shouldn't contain 'user'. Please change your Password!!!";
                }
                else if (!regPass.IsMatch(tbxNewPass.Text))
                {
                    lblNewPassError.Text = "Password must satisfy this conditions: minimum 8 characters long A-Z, 1 uppercase, 1 lowercase character, 1 number and 1 special character (!.@#$%^&+=)";
                }
                else if (tbxNewPass.Text != tbxConfirmNewPass.Text)
                {
                    lblNewPassError.Text = "Your password and password confirmation do not match!";
                }
                else
                {
                    using (var SCDB = new CroscoStopCardEntities())
                    {
                        string username = (string)Session["UserName"];
                        var    result   = SCDB.Users.SingleOrDefault(b => b.UserName == username);

                        if (result != null)
                        {
                            Session["UserName"]    = null;
                            Session["NewPassword"] = null;

                            result.Lozinka = PasswordHash.CreateHash(tbxNewPass.Text);
                            SCDB.SaveChanges();

                            if (result.UserRole == "Admin" || result.UserRole == "LocalAdmin" || result.UserRole == "Manager" || result.UserRole == "MasterAdmin")
                            {
                                Session["UserRole"] = result.UserRole;
                            }
                            else
                            {
                                Session["user"] = result.UserName;
                            }

                            Session["userID"] = result.UserID;
                            Response.Redirect("StopQueryPage.aspx");
                        }
                    }
                }
            }
            else
            {
                lblNewPassError.Text = "Password and password confirmation are required!";
            }
        }
示例#2
0
        protected void GVUsers_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            CroscoStopCardEntities stopCardEntities = new CroscoStopCardEntities();

            var result = stopCardEntities.Users.Select(x => new { x.UserID, x.Lozinka }).Where(x => x.UserID == EditUserID);

            TextBox tbxPassEdit = GVUsers.Rows[e.RowIndex].FindControl("tbxPassEdit") as TextBox;

            if (tbxPassEdit.Text != result.Select(x => x.Lozinka).FirstOrDefault())
            {
                e.NewValues.Remove("Lozinka");
                e.NewValues.Add("Lozinka", PasswordHash.CreateHash(tbxPassEdit.Text));
            }
            e.NewValues.Add("UserRole", ((DropDownList)GVUsers.Rows[e.RowIndex].FindControl("ddlUserRole")).SelectedValue);
            e.NewValues.Add("OJ", ((DropDownList)GVUsers.Rows[e.RowIndex].FindControl("ddlOJ")).SelectedValue);
        }
示例#3
0
        protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            TextBox tbxLN         = DetailsView1.FindControl("tbxLN") as TextBox;
            TextBox tbxMB         = DetailsView1.FindControl("tbxMB") as TextBox;
            TextBox tbxPassInsert = DetailsView1.FindControl("tbxPassInsert") as TextBox;
            int     checkMB       = 0;

            Regex regPass  = new Regex(@"^.*(?=.{8,50})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!.@#$%^&+=]).*$");
            Regex regEmail = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");

            string Username = tbxLN.Text.ToLower() + "." + tbxMB.Text;

            using (var SCDB = new CroscoStopCardEntities())
            {
                var listUsers = SCDB.Users.Select(x => x.UserName.ToLower()).ToArray();

                if (listUsers.Contains(Username))
                {
                    GetErrorText     = "This Username: (" + Username + ") already exist!";
                    lblError.Text    = GetErrorText;
                    lblError.Visible = true;
                    e.Cancel         = true;
                }
            }

            if (string.IsNullOrWhiteSpace(((TextBox)DetailsView1.FindControl("tbxFN")).Text))
            {
                error.AppendLine("First Name is Required");
                valid = false;
            }
            if (string.IsNullOrWhiteSpace(tbxLN.Text))
            {
                error.AppendLine("Last Name is Required");
                valid = false;
            }
            if (string.IsNullOrWhiteSpace(tbxPassInsert.Text))
            {
                error.AppendLine("Password is Required");
                valid = false;
            }
            if (string.IsNullOrWhiteSpace(tbxMB.Text))
            {
                error.AppendLine("Matični Broj is Required");
                valid = false;
            }

            if (!int.TryParse(tbxMB.Text, out checkMB))
            {
                error.AppendLine("Matični Broj must be a number!");
                valid = false;
            }
            else
            {
                using (var SCDB = new CroscoStopCardEntities())
                {
                    var listMB = SCDB.Users.Select(x => x.MaticniBroj).ToArray();

                    if (listMB.Contains(checkMB))
                    {
                        GetErrorText     = "There are already user with this Matični Broj: (" + checkMB + ")!";
                        lblError.Text    = GetErrorText;
                        lblError.Visible = true;
                        e.Cancel         = true;
                    }
                }
            }

            if (!regPass.IsMatch(tbxPassInsert.Text))
            {
                error.AppendLine("Password must satisfy this conditions: minimum 8 characters long A-Z, 1 uppercase, 1 lowercase character, 1 number and 1 special character (!.@#$%^&+=)");
                valid = false;
            }

            TextBox tbxEmail = DetailsView1.FindControl("tbxMail") as TextBox;

            if (!string.IsNullOrEmpty(tbxEmail.Text))
            {
                if (!regEmail.IsMatch(tbxEmail.Text))
                {
                    error.AppendLine("Entered Email address is not valid!");
                    valid = false;
                }
            }

            if (!valid)
            {
                GetErrorText     = error.ToString();
                lblError.Text    = GetErrorText;
                lblError.Visible = true;
                e.Cancel         = true;
            }

            e.Values.Remove("Lozinka");
            e.Values.Remove("UserName");
            e.Values.Add("Lozinka", PasswordHash.CreateHash(tbxPassInsert.Text));
            e.Values.Add("UserName", Username);
            e.Values.Add("UserRole", ((DropDownList)DetailsView1.FindControl("ddlUserRole")).SelectedValue);
            e.Values.Add("OJ", ((DropDownList)DetailsView1.FindControl("ddlOJ")).SelectedValue);
        }
示例#4
0
        protected void btnImportUsers_Click(object sender, EventArgs e)
        {
            if (fuExcel.FileName != string.Empty)
            {
                if (fuExcel.FileName.ToLower().EndsWith(".xls") || fuExcel.FileName.ToLower().EndsWith(".xlsx"))
                {
                    fuExcel.SaveAs(Server.MapPath("~/TempFiles/") + fuExcel.FileName);

                    string filePath = Server.MapPath("~/TempFiles/") + fuExcel.FileName;

                    IWorkbook workbook;
                    if (fuExcel.FileName.ToLower().EndsWith(".xls"))
                    {
                        using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                            workbook = new HSSFWorkbook(stream);
                    }
                    else
                    {
                        using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                            workbook = new XSSFWorkbook(stream);
                    }

                    ISheet    sheet = workbook.GetSheetAt(0);
                    DataTable dt    = new DataTable(sheet.SheetName);

                    IRow headerRow = sheet.GetRow(0);
                    foreach (ICell headerCell in headerRow)
                    {
                        dt.Columns.Add(headerCell.ToString());
                    }

                    int rowIndex = 0;
                    foreach (IRow row in sheet)
                    {
                        if (rowIndex++ == 0)
                        {
                            continue;
                        }
                        DataRow dataRow = dt.NewRow();
                        dataRow.ItemArray = row.Cells.Select(c => c.ToString()).ToArray();
                        dt.Rows.Add(dataRow);
                    }

                    using (var SCDB = new CroscoStopCardEntities())
                    {
                        //int lastID = SCDB.Users.OrderByDescending(u => u.UserID).FirstOrDefault().UserID;
                        var listUsers = SCDB.Users.Select(x => x.UserName).ToArray();

                        for (int i = 0; i < dt.Rows.Count - 1; i++)
                        {
                            DataRow dr = dt.Rows[i];

                            if (listUsers.Contains(dr["UserName"].ToString()))
                            {
                                continue;
                            }

                            try
                            {
                                if ((string)Session["UserRole"] == "Admin")
                                {
                                    SCDB.Users.Add(new User()
                                    {
                                        FirstName   = dr["FirstName"].ToString(),
                                        LastName    = dr["LastName"].ToString(),
                                        UserName    = dr["UserName"].ToString(),
                                        Lozinka     = PasswordHash.CreateHash(dr["Lozinka"].ToString()),
                                        MaticniBroj = Convert.ToInt32(dr["MaticniBroj"]),
                                        OJ          = (string)Session["OJ"],
                                        SubOJ       = dr["SubOJ"].ToString(),
                                        SubOJDva    = dr["SubOJDva"].ToString(),
                                        Email       = dr["Email"].ToString(),
                                        UserRole    = "User"
                                    });
                                }
                                else
                                {
                                    SCDB.Users.Add(new User()
                                    {
                                        //UserID = ++lastID,
                                        FirstName   = dr["FirstName"].ToString(),
                                        LastName    = dr["LastName"].ToString(),
                                        UserName    = dr["UserName"].ToString(),
                                        Lozinka     = PasswordHash.CreateHash(dr["Lozinka"].ToString()),
                                        MaticniBroj = Convert.ToInt32(dr["MaticniBroj"]),
                                        OJ          = dr["OJ"].ToString(),
                                        SubOJ       = dr["SubOJ"].ToString(),
                                        SubOJDva    = dr["SubOJDva"].ToString(),
                                        Email       = dr["Email"].ToString(),
                                        UserRole    = dr["UserRole"].ToString()
                                    });
                                }
                            }
                            catch (Exception ex)
                            {
                                GetErrorText     = ex.Message;
                                lblError.Text    = GetErrorText;
                                lblError.Visible = true;
                            }
                        }
                        try
                        {
                            SCDB.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            GetErrorText     = ex.Message;
                            lblError.Text    = GetErrorText;
                            lblError.Visible = true;
                        }
                    }
                    File.Delete(filePath);

                    Response.Redirect("AdminPage.aspx");
                }
                else
                {
                    GetErrorText     = "Please choose an .xls or .xlsx file!";
                    lblError.Text    = GetErrorText;
                    lblError.Visible = true;
                }
            }
            else
            {
                GetErrorText     = "Please upload .xls or .xlsx file first!";
                lblError.Text    = GetErrorText;
                lblError.Visible = true;
            }
        }