Ejemplo n.º 1
0
        public ActionResult SendConfirmEmail(string id)
        {
            string stamp = Guid.NewGuid().ToString();
            string body  = string.Format(@"http://localhost:62844/Administration/ConfirmEmail?Id={0}&stamp={1}", id, stamp);

            if (WWIDal.UpdateSecurityStamp(id, stamp))
            {
                WWIDal dal = new WWIDal();
                AspNetEditUserModel model = dal.GetUser(id);
                MailHelper.SendMail(WWIDal.GetUserEmail(id), body, "Email Confirmation for " + model.UserName);
            }
            return(RedirectToAction("EditUser", new { Id = id }));
        }
Ejemplo n.º 2
0
        public ActionResult EditUser(AspNetEditUserModel model)
        {
            try
            {
                WWIDal dal             = new WWIDal();
                int    recordsEffected = dal.UpdateUser(model);
            }
            catch (Exception ex)
            {
                Logger.LogError("EditUser Post exception: ", ex);
            }

            return(RedirectToAction("Users"));
        }
Ejemplo n.º 3
0
        public int UpdateUser(AspNetEditUserModel model)
        {
            int           _ret = 0;
            SQLData       db   = new SQLData();
            StringBuilder sb   = new StringBuilder(@"UPDATE dbo.AspNetUsers SET Email=@Email, EmailConfirmed=@EmailConfirmed,
							PhoneNumber=@PhoneNumber, PhoneNumberConfirmed=@PhoneNumberConfirmed, TwoFactorEnabled=@TwoFactorEnabled, 
							LockoutEnabled=@LockoutEnabled, LockoutEndDateUtc=@LockoutEndDateUtc, AccessFailedCount=@AccessFailedCount"                            );

            sb.Append(" WHERE Id=@Id");

            try
            {
                List <SqlParameter> parms = new List <SqlParameter>();
                parms.Add(new SqlParameter("@Email", model.Email));
                parms.Add(new SqlParameter("@EmailConfirmed", model.EmailConfirmed));
                parms.Add(new SqlParameter("@PhoneNumber", (string.IsNullOrEmpty(model.PhoneNumber)) ? "" : model.PhoneNumber));
                parms.Add(new SqlParameter("@PhoneNumberConfirmed", model.PhoneNumberConfirmed));
                parms.Add(new SqlParameter("@TwoFactorEnabled", model.TwoFactorEnabled));
                parms.Add(new SqlParameter("@LockoutEnabled", model.LockoutEnabled));
                parms.Add(new SqlParameter("@LockoutEndDateUtc", model.LockoutEndDateUtc));
                parms.Add(new SqlParameter("@AccessFailedCount", model.AccessFailedCount));
                parms.Add(new SqlParameter("@Id", model.Id));

                db.Open(ConfigurationManager.ConnectionStrings["WWI"].ConnectionString);
                _ret = db.ExecuteNonQuery(sb.ToString(), parms);

                string roleName        = "Administrator";
                bool   userHasRoleName = WWIDal.UserHasRoleName(model.Id, roleName);
                if (model.cbAdministrator && !userHasRoleName)
                {
                    InsertUserRole(model.Id, roleName);
                }
                else if (!model.cbAdministrator && userHasRoleName)
                {
                    DeleteUserRole(model.Id, roleName);
                }

                roleName        = "Contractor";
                userHasRoleName = WWIDal.UserHasRoleName(model.Id, roleName);
                if (model.cbContractor && !userHasRoleName)
                {
                    InsertUserRole(model.Id, roleName);
                }
                else if (!model.cbAdministrator && userHasRoleName)
                {
                    DeleteUserRole(model.Id, roleName);
                }

                roleName        = "Executive";
                userHasRoleName = WWIDal.UserHasRoleName(model.Id, roleName);
                if (model.cbExecutive && !userHasRoleName)
                {
                    InsertUserRole(model.Id, roleName);
                }
                else if (!model.cbExecutive && userHasRoleName)
                {
                    DeleteUserRole(model.Id, roleName);
                }

                roleName        = "Inventory";
                userHasRoleName = WWIDal.UserHasRoleName(model.Id, roleName);
                if (model.cbInventory && !userHasRoleName)
                {
                    InsertUserRole(model.Id, roleName);
                }
                else if (!model.cbInventory && userHasRoleName)
                {
                    DeleteUserRole(model.Id, roleName);
                }

                roleName        = "Sales";
                userHasRoleName = WWIDal.UserHasRoleName(model.Id, roleName);
                if (model.cbSales && !userHasRoleName)
                {
                    InsertUserRole(model.Id, roleName);
                }
                else if (!model.cbSales && userHasRoleName)
                {
                    DeleteUserRole(model.Id, roleName);
                }

                roleName        = "Supplier";
                userHasRoleName = WWIDal.UserHasRoleName(model.Id, roleName);
                if (model.cbSupplier && !userHasRoleName)
                {
                    InsertUserRole(model.Id, roleName);
                }
                else if (!model.cbSupplier && userHasRoleName)
                {
                    DeleteUserRole(model.Id, roleName);
                }

                roleName        = "User";
                userHasRoleName = WWIDal.UserHasRoleName(model.Id, roleName);
                if (model.cbUser && !userHasRoleName)
                {
                    InsertUserRole(model.Id, roleName);
                }
                else if (!model.cbUser && userHasRoleName)
                {
                    DeleteUserRole(model.Id, roleName);
                }

                roleName        = "Vendor";
                userHasRoleName = WWIDal.UserHasRoleName(model.Id, roleName);
                if (model.cbVendor && !userHasRoleName)
                {
                    InsertUserRole(model.Id, roleName);
                }
                else if (!model.cbVendor && userHasRoleName)
                {
                    DeleteUserRole(model.Id, roleName);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("UpdateUser exception: ", ex);
            }
            finally
            {
                db.Close();
            }

            return(_ret);
        }
Ejemplo n.º 4
0
        public AspNetEditUserModel GetUser(string id)
        {
            AspNetEditUserModel model = new AspNetEditUserModel();

            SQLData             db    = new SQLData();
            string              sql   = "SELECT * FROM dbo.AspNetUsers WHERE Id=@Id";
            List <SqlParameter> parms = new List <SqlParameter>();

            try
            {
                db.Open(ConfigurationManager.ConnectionStrings["WWI"].ConnectionString);
                parms.Add(new SqlParameter("@Id", id));
                DataTable dt  = db.Execute(sql, parms);
                DataRow   row = dt.Rows[0];

                if (!row["Id"].ToString().Equals(string.Empty))
                {
                    model.Id = row["Id"].ToString();
                }

                if (!row["UserName"].ToString().Equals(string.Empty))
                {
                    model.UserName = row["UserName"].ToString();
                }

                if (!row["Email"].ToString().Equals(string.Empty))
                {
                    model.Email = row["Email"].ToString();
                }

                if (!row["EmailConfirmed"].ToString().Equals(string.Empty))
                {
                    model.EmailConfirmed = (Boolean)row["EmailConfirmed"];
                }

                if (!row["SecurityStamp"].ToString().Equals(string.Empty))
                {
                    model.SecurityStamp = row["SecurityStamp"].ToString();
                }

                if (!row["PhoneNumber"].ToString().Equals(string.Empty))
                {
                    model.PhoneNumber = row["PhoneNumber"].ToString();
                }

                if (!row["PhoneNumberConfirmed"].ToString().Equals(string.Empty))
                {
                    model.PhoneNumberConfirmed = (Boolean)row["PhoneNumberConfirmed"];
                }

                if (!row["TwoFactorEnabled"].ToString().Equals(string.Empty))
                {
                    model.TwoFactorEnabled = (Boolean)row["TwoFactorEnabled"];
                }

                if (!row["LockoutEndDateUtc"].ToString().Equals(string.Empty))
                {
                    model.LockoutEndDateUtc = (DateTime)row["LockoutEndDateUtc"];
                }
                else
                {
                    model.LockoutEndDateUtc = DateTime.Now;
                }

                if (!row["LockoutEnabled"].ToString().Equals(string.Empty))
                {
                    model.LockoutEnabled = (Boolean)row["LockoutEnabled"];
                }

                if (!row["AccessFailedCount"].ToString().Equals(string.Empty))
                {
                    model.AccessFailedCount = (Int32)row["AccessFailedCount"];
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("GetUser exception: ", ex);
            }

            return(model);
        }