示例#1
0
 private void CreateMember(string email,string password,string role,string firstName)
 {
     IdentityManager identity = new IdentityManager();
     var adminUser = identity.GetUser(email);
     if(adminUser == null) {
         string errorResult = string.Empty;
         if(identity.CreateUser(email,password,out errorResult)) {
             adminUser = identity.GetUser(email);
             if(adminUser != null) {
                 identity.AddUserToRole(adminUser.Id,role);
                 using(WVCContext context = new WVCContext()) {
                     var wvcUser = context.wvc_user.FirstOrDefault(q => q.aspnetuser_id == adminUser.Id);
                     if(wvcUser == null) {
                         wvcUser = new wvc_user();
                         wvcUser.aspnetuser_id = adminUser.Id;
                         wvcUser.created_date = DateTime.Now;
                         wvcUser.first_name = firstName;
                         wvcUser.is_active = true;
                         wvcUser.Save();
                     }
                 }
             }
         }
     }
 }
示例#2
0
        public ActionResult EditUser(ApplicationUser usr,bool user,bool admin)
        {
            var im = new IdentityManager();
            var db = new ApplicationDbContext();
            ApplicationUser userEdit = db.Users.FirstOrDefault(m => m.Id == usr.Id); ;
            userEdit.Email = usr.Email;
            userEdit.AdvOnPg = usr.AdvOnPg;
            userEdit.PhoneNumber = usr.PhoneNumber;
            db.SaveChanges();
            if(!user&&im.InRole(usr.Id,"User"))
            {
                im.RemoveFromRole(usr.Id, "User");
            }

            if (user && !im.InRole(usr.Id, "User"))
            {
                im.AddUserToRole(usr.Id, "User");
            }

            if (!admin && im.InRole(usr.Id, "Admin"))
            {
                im.RemoveFromRole(usr.Id, "Admin");
            }

            if (user && !im.InRole(usr.Id, "Admin"))
            {
                im.AddUserToRole(usr.Id, "Admin");
            }

            return RedirectToAction("Users");
        }
示例#3
0
        public async Task<ActionResult> UserRoles(SelectUserRolesViewModel model)
        {
            if (ModelState.IsValid)
            {
                var idManager = new IdentityManager();
                var Db = new ApplicationDbContext();
                var user = Db.Users.First(u => u.Id == model.Id);
                await idManager.ClearUserRoles(user.Id);
                foreach (var role in model.Roles)
                {
                    if (role.Selected)
                    {
                        idManager.AddUserToRole(user.Id, role.RoleName);
                    }

                }
                return RedirectToAction("index");
            }

            return View();

        }
示例#4
0
        bool AddUserAndRoles()
        {
            bool success = false;

            var idManager = new IdentityManager();

            success = idManager.CreateRole("Admin");
            if (!success == true)
            {
                return(success);
            }

            success = idManager.CreateRole("CanEdit");
            if (!success == true)
            {
                return(success);
            }

            success = idManager.CreateRole("User");
            if (!success)
            {
                return(success);
            }


            var newUser = new ApplicationUser()
            {
                UserName  = "******",
                FirstName = "Dustin",
                LastName  = "Falgout",
                Email     = "*****@*****.**"
            };

            // Be careful here - you  will need to use a password which will
            // be valid under the password rules for the application,
            // or the process will abort:
            success = idManager.CreateUser(newUser, "Password");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser.Id, "Admin");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser.Id, "CanEdit");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser.Id, "User");
            if (!success)
            {
                return(success);
            }

            return(success);
        }
示例#5
0
        bool AddUserAndRoles()
        {
            bool success = false;

            var idManager = new IdentityManager();

            success = idManager.CreateRole("Admin");
            if (!success == true)
            {
                return(success);
            }

            success = idManager.CreateRole("CanEdit");
            if (!success == true)
            {
                return(success);
            }

            success = idManager.CreateRole("User");
            if (!success)
            {
                return(success);
            }


            var newUser = new ApplicationUser()
            {
                UserName        = "******",
                ApellidoPaterno = "QUISPE",
                ApellidoMaterno = "PALOMINO",
                Nombres         = "JUAN PEREZ"
            };

            // Be careful here - you  will need to use a password which will
            // be valid under the password rules for the application,
            // or the process will abort:
            success = idManager.CreateUser(newUser, "Password1");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser.Id, "Admin");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser.Id, "CanEdit");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser.Id, "User");
            if (!success)
            {
                return(success);
            }

            return(success);
        }
        public static void AddUsers()
        {
            _dbContext.Database.ExecuteSqlCommand("delete IdentityManager");
            var idManager = new IdentityManager();

            #region 管理员
            var person1 = new Person()
            {
                FirstName       = "大",
                LastName        = "毛",
                Name            = "大毛",
                CredentialsCode = "450000199901010101",
                Birthday        = DateTime.Parse("1999-01-01"),
                Sex             = true,
                MobileNumber    = "11111111",
                Email           = "[email protected]",
                CreateDateTime  = DateTime.Now,
                TelephoneNumber = "123456789",
                Description     = "超级管理员",
                UpdateTime      = DateTime.Now,
                InquiryPassword = "******",
            };
            var loginUser = new ApplicationUser()
            {
                UserName        = "******",
                FirstName       = "大",
                LastName        = "毛",
                ChineseFullName = "大毛",
                MobileNumber    = "11111111",
                Email           = "[email protected]",
                Person          = person1
            };
            //缺省配置,密码大于6位,字母数字特殊符号,否则不能创建用户
            idManager.CreateUser(loginUser, "123.abc");
            //添加到Admin角色
            idManager.AddUserToRole(loginUser.Id, "Admin");
            #endregion

            #region 注册用户

            var person2 = new Person()
            {
                FirstName       = "二",
                LastName        = "毛",
                Name            = "二毛",
                CredentialsCode = "450000199901010101",
                Birthday        = DateTime.Parse("1999-01-01"),
                Sex             = true,
                MobileNumber    = "11111111",
                Email           = "[email protected]",
                CreateDateTime  = DateTime.Now,
                TelephoneNumber = "123456789",
                Description     = "超级管理员",
                UpdateTime      = DateTime.Now,
                InquiryPassword = "******",
            };
            var newUser2 = new ApplicationUser()
            {
                UserName        = "******",
                FirstName       = "二",
                LastName        = "毛",
                ChineseFullName = "二毛",
                MobileNumber    = "11111111",
                Email           = "[email protected]",
                Person          = person1
            };
            idManager.CreateUser(newUser2, "123.abc");
            idManager.AddUserToRole(newUser2.Id, "RegisterUser");

            #endregion 注册用户

            #region 业务管理



            #endregion 业务管理
        }
示例#7
0
        public void BatchImportAccount(string[] accountList)
        {
            foreach (var mail in accountList)
            {
                // check membership data existed or not
                try
                {
                    var profile = SSOAuthHelper.GetAdvantechMemberProfile(mail);
                    if (profile != null)
                    {
                        var appUser = SSOAuthHelper.MappingSSOProfileToAppuser(profile, mail);
                        if (SSOAuthHelper.IsEmployee(appUser.Email))
                        {
                            var mngr        = new IdentityManager();
                            var existedUser = mngr.GetUserByEmail(mail);
                            if (existedUser == null)
                            {
                                //create new user
                                //var password = "******";
                                //if (LoginTicket != null) // if SSO, set password = null
                                //    password = null;
                                var succeed = mngr.CreateUser(appUser, null);

                                //add one role to this user
                                if (succeed)
                                {
                                    //get selected role-Ids
                                    if (!string.IsNullOrEmpty(this.SelectedRoleId))
                                    {
                                        var role = mngr.GetRoleByRoleId(this.SelectedRoleId);
                                        appUser = mngr.GetUserByName(appUser.UserName);
                                        succeed = mngr.AddUserToRole(appUser.Id, role.Name);
                                        if (!succeed)
                                        {
                                            throw new HttpException(608, string.Format("Role [{0}] could not be assigned.", role.Name));
                                        }
                                    }
                                }
                                else
                                {
                                    throw new HttpException(608, string.Format("Creat user {0} fail.", this.User.Email));
                                }
                            }
                            else
                            {
                                throw new HttpException(608, string.Format("User {0} is existed in eQuotation.", this.User.Email));
                            }
                        }
                        else
                        {
                            throw new HttpException(608, string.Format("User {0} is not the employee of Advantech.", this.User.Email));
                        }
                    }
                    else
                    {
                        throw new HttpException(608, string.Format("User {0} is not the member of Advantech.", this.User.Email));
                    }
                }
                catch { };
            }
        }
示例#8
0
        public override void SetValue()
        {
            if (!HasEntity(this.User.Id))
            {
                if (this.UnitWork.AppUser.Exists(x => x.UserName == this.User.UserName))
                {
                    throw new HttpException(608, "UserName has been used.");
                }

                // check membership data existed or not
                var profile = SSOAuthHelper.GetAdvantechMemberProfile(this.User.Email);
                if (profile != null)
                {
                    var appUser = SSOAuthHelper.MappingSSOProfileToAppuser(profile, this.User.Email);
                    if (SSOAuthHelper.IsEmployee(appUser.Email))
                    {
                        var mngr        = new IdentityManager();
                        var existedUser = mngr.GetUserByEmail(this.User.Email);
                        if (existedUser == null)
                        {
                            //create new user
                            var succeed = mngr.CreateUser(appUser, null);

                            //add one role to this user
                            if (succeed)
                            {
                                //get selected role-Ids
                                if (!string.IsNullOrEmpty(this.SelectedRoleId))
                                {
                                    var role = mngr.GetRoleByRoleId(this.SelectedRoleId);
                                    appUser = mngr.GetUserByName(appUser.UserName);
                                    succeed = mngr.AddUserToRole(appUser.Id, role.Name);
                                    if (!succeed)
                                    {
                                        throw new HttpException(608, string.Format("Role [{0}] could not be assigned.", role.Name));
                                    }
                                }
                            }
                            else
                            {
                                throw new HttpException(608, string.Format("Creat user {0} fail.", this.User.Email));
                            }
                        }
                        else
                        {
                            throw new HttpException(608, string.Format("User {0} is existed in eQuotation.", this.User.Email));
                        }
                    }
                    else
                    {
                        throw new HttpException(608, string.Format("User {0} is not the employee of Advantech.", this.User.Email));
                    }
                }
                else
                {
                    throw new HttpException(608, string.Format("User {0} is not the member of Advantech.", this.User.Email));
                }
            }
            else
            {
                //update existing user attributes
                Entity.Id         = this.User.Id;
                Entity.FirstName  = this.User.FirstName;
                Entity.LastName   = this.User.LastName;
                Entity.Position   = this.User.Position;
                Entity.Department = this.User.Department;
                Entity.Company    = this.User.Company;
                Entity.Location   = this.User.Location;
                Entity.Email      = this.User.Email;

                this.UnitWork.AppUser.Update(Entity);
            }
        }
示例#9
0
        protected override void Seed(IAS.Models.ApplicationDbContext context)
        {
            //Roles
            var identityManager = new IdentityManager();

            identityManager.CreateRole("Identity Manager");
            identityManager.CreateRole("Master Data Manager");
            var elio = context.Users.SingleOrDefault(u => u.UserName == "elio");

            if (null != elio)
            {
                identityManager.AddUserToRole(elio.Id, "Identity Manager");
            }

            var marco = context.Users.SingleOrDefault(u => u.UserName == "marco");

            if (null != marco)
            {
                identityManager.AddUserToRole(marco.Id, "Identity Manager");
            }

            // Usuarios
            var store   = new UserStore <ApplicationUser>(context);
            var manager = new UserManager <ApplicationUser>(store);
            var user    = new ApplicationUser
            {
                UserName  = "******",
                FirstName = "Elio",
                LastName  = "Batista",
                Email     = "*****@*****.**",
                Phone     = "123456,789456"
            };

            manager.Create(user, "cuban*");

            var user2 = new ApplicationUser
            {
                UserName  = "******",
                FirstName = "Marco",
                LastName  = "Gulino",
                Email     = "*****@*****.**",
                Phone     = "0993595988"
            };

            manager.Create(user2, "futb*l");

            var user3 = new ApplicationUser
            {
                UserName  = "******",
                FirstName = "Christian",
                LastName  = "Balbuena",
                Email     = "*****@*****.**",
                Phone     = "123456,789456"
            };

            manager.Create(user3, "@zure1");

            //context.Database.ExecuteSqlCommand("update AspNetUsers set FirstName ='Nombre', LastName='Apellido',Email='*****@*****.**',Phone='123456,789456'");
            // CasePriority
            context.CasePriorities.AddOrUpdate(
                s => s.PriorityName,
                new CasePriority
            {
                PriorityName = "Alta"
            },
                new CasePriority
            {
                PriorityName = "Media"
            },
                new CasePriority
            {
                PriorityName = "Baja"
            }
                );
            // State
            context.States.AddOrUpdate(
                s => s.StateName,
                new State
            {
                StateName = "Pendiente",
                Active    = true
            },
                new State
            {
                StateName = "Incontactable",
                Active    = true
            },
                new State
            {
                StateName = "Promesa de pago",
                Active    = true
            },
                new State
            {
                StateName = "Pago realizado",
                Active    = true
            },
                new State
            {
                StateName = "Volver a contactar",
                Active    = true
            },
                new State
            {
                StateName = "Pago condicionado",
                Active    = true
            },
                new State
            {
                StateName = "Condición de pago procesada",
                Active    = true
            },
                new State
            {
                StateName = "Condición de pago inviable",
                Active    = true
            },
                new State
            {
                StateName = "Pago no registrado",
                Active    = true
            },
                new State
            {
                StateName = "Notificado al cliente",
                Active    = true
            },
                new State
            {
                StateName = "Notificado a la aseguradora",
                Active    = true
            }
                );

            // Workflow
            var wf1 = new Workflow
            {
                WorkflowName = "Siniestros"
            };
            var wf2 = new Workflow
            {
                WorkflowName = "Cobranzas"
            };

            var wf3 = new Workflow
            {
                WorkflowName = "Renovaciones"
            };

            context.Workflows.AddOrUpdate(
                w => w.WorkflowName,
                wf1, wf2, wf3
                );

            // Forms
            context.Forms.AddOrUpdate(
                f => f.FormName,
                new Form
            {
                FormName = "SiniestroCargaFotoForm",
                Url      = "SiniestroCargaFotoForm.aspx"
                           //,Workflow = wf1
            },
                new Form
            {
                FormName = "CobranzaLlamadaForm",
                Url      = "CobranzaLlamadaForm.aspx"
                           //,Workflow = wf2
            },
                new Form
            {
                FormName = "NuevoClienteForm",
                Url      = "NuevoClienteForm.aspx"
                           //,Workflow = wf3
            }
                );

            // Money
            context.Currencies.AddOrUpdate(
                s => s.Code,
                new Currency
            {
                Code         = "PYG",
                Denomination = "Guaranies"
            },
                new Currency
            {
                Code         = "USD",
                Denomination = "Dolares"
            }
                );

            // CollectionState
            context.CollectionStates.AddOrUpdate(
                s => s.CollectionStateName,
                new CollectionState
            {
                CollectionStateName = "Cobrado"
            },
                new CollectionState
            {
                CollectionStateName = "Vencido"
            }
                ,
                new CollectionState
            {
                CollectionStateName = "A vencer"
            },
                new CollectionState
            {
                CollectionStateName = "Corroborar pago"
            }
                );

            // CollectionState
            context.CollectionMethods.AddOrUpdate(
                s => s.CollectionMethodName,
                new CollectionMethod
            {
                Code = "IN",
                CollectionMethodName = "Indeterminado"
            },
                new CollectionMethod
            {
                Code = "CO",
                CollectionMethodName = "Cobrador"
            }
                ,
                new CollectionMethod
            {
                Code = "TA",
                CollectionMethodName = "Tarjeta"
            },
                new CollectionMethod
            {
                Code = "DB",
                CollectionMethodName = "Debito"
            }
                );

            //context.Database.ExecuteSqlCommand( "update collection set CollectionMethodID=1" );
            //context.AppConfigs.AddOrUpdate(
            //     cfg => cfg.CollectionWorkflowID,
            //     new AppConfig
            //     {
            //         CollectionWorkflow = context.Workflows.Where( w => w.WorkflowID == 2 ).First(),
            //         DefaultCasePriority = context.CasePriorities.First(),
            //         CollectionInitialState = context.States.Single( s => s.StateID == 1 ),
            //         CollectionFinalState = context.States.Single( s => s.StateID == 4 ),
            //         DefaultUser = marco,
            //         EffectiveDaysThreshold = 2
            //     }
            // );

            //DocumentType & Person Bulk Data
            //var dirBase = AppDomain.CurrentDomain.BaseDirectory.Replace(@"\bin", string.Empty) + @"\Migrations";
            //context.Database.ExecuteSqlCommand(File.ReadAllText(dirBase + @"\ExchangeSchemaData.sql"));

            // Workflow states transition
            //context.WorkflowStateTransitions.AddOrUpdate(
            //    wt => wt.WorkflowID,
            //    new WorkflowStateTransition
            //    {
            //        WorkflowID = context.Workflows.Take(1).Single().WorkflowID,
            //        InitialStateID = context.States.Take(1).Single().StateID,
            //        FinalStateID = context.States.Take(2).Last().StateID,
            //    },
            //    new WorkflowStateTransition
            //    {
            //        WorkflowID = context.Workflows.Take(1).Single().WorkflowID,
            //        InitialStateID = context.States.Take(2).Last().StateID,
            //        FinalStateID = context.States.Take(3).Last().StateID,
            //    }
            //);
        }
示例#10
0
        bool AddUserAndRoles()
        {
            bool success = false;
            var  context = new ApplicationDbContext();

            var idManager = new IdentityManager();

            success = idManager.CreateRole("Admin");
            if (!success == true)
            {
                return(success);
            }

            success = idManager.CreateRole("CanEdit");
            if (!success == true)
            {
                return(success);
            }

            success = idManager.CreateRole("User");
            if (!success)
            {
                return(success);
            }


            var newUser = new ApplicationUser()
            {
                UserName  = "******",
                FirstName = "Marcin",
                LastName  = "Stanek",
                Email     = "*****@*****.**"
            };

            success = idManager.CreateUser(newUser, "Koalicja1");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser.Id, "Admin");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser.Id, "CanEdit");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser.Id, "User");
            if (!success)
            {
                return(success);
            }

            ///////////////////////////////////////////////////////////////////////

            var newUser1 = new ApplicationUser()
            {
                UserName  = "******",
                FirstName = "Admin",
                LastName  = "Admin",
                Email     = "*****@*****.**"
            };

            success = idManager.CreateUser(newUser1, "Password1");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser1.Id, "Admin");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser1.Id, "CanEdit");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser1.Id, "User");
            if (!success)
            {
                return(success);
            }

            ///////////////////////////////////////////////////////////////////////

            var newUser2 = new ApplicationUser()
            {
                UserName  = "******",
                FirstName = "Wojtek",
                LastName  = "Kempisty",
                Email     = "*****@*****.**"
            };

            success = idManager.CreateUser(newUser2, "Password1");
            if (!success)
            {
                return(success);
            }


            success = idManager.AddUserToRole(newUser2.Id, "CanEdit");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser2.Id, "User");
            if (!success)
            {
                return(success);
            }

            ///////////////////////////////////////////////////////////////////////

            var newUser3 = new ApplicationUser()
            {
                UserName  = "******",
                FirstName = "Kamil",
                LastName  = "Grzywa",
                Email     = "*****@*****.**"
            };

            success = idManager.CreateUser(newUser3, "Password1");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser3.Id, "CanEdit");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser3.Id, "User");
            if (!success)
            {
                return(success);
            }

            ///////////////////////////////////////////////////////////////////////

            var newUser4 = new ApplicationUser()
            {
                UserName  = "******",
                FirstName = "Michal",
                LastName  = "Sztaba",
                Email     = "*****@*****.**"
            };

            success = idManager.CreateUser(newUser4, "Password1");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser4.Id, "User");
            if (!success)
            {
                return(success);
            }

            ///////////////////////////////////////////////////////////////////////

            var newUser5 = new ApplicationUser()
            {
                UserName  = "******",
                FirstName = "Justyna",
                LastName  = "Jakubas",
                Email     = "*****@*****.**"
            };

            success = idManager.CreateUser(newUser5, "Password1");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser5.Id, "User");
            if (!success)
            {
                return(success);
            }

            return(success);
        }
示例#11
0
        public static bool AddUserAndRoles()
        {
            bool success = false;

            var idManager = new IdentityManager();
            var role1     = new ApplicationRole()
            {
                Name = "Admin", DisplayName = "系统管理员组", Description = "具备全部权限的用户组", SortCode = "001"
            };

            success = idManager.CreateRole(role1);
            if (!success == true)
            {
                return(success);
            }

            var role2 = new ApplicationRole()
            {
                Name = "CanEdit", DisplayName = "业务数据编辑管理组", Description = "具备编辑一般业务数据权限的用户组", SortCode = "002"
            };

            success = idManager.CreateRole(role2);
            if (!success == true)
            {
                return(success);
            }

            var role3 = new ApplicationRole()
            {
                Name = "User", DisplayName = "内部用户", Description = "内部操作用户组", SortCode = "003"
            };

            success = idManager.CreateRole(role3);
            if (!success)
            {
                return(success);
            }

            var role4 = new ApplicationRole()
            {
                Name = "CustomerUser", DisplayName = "外部用户", Description = "外部操作用户组", SortCode = "004"
            };

            success = idManager.CreateRole(role4);
            if (!success)
            {
                return(success);
            }


            var newUser = new ApplicationUser()
            {
                UserName        = "******",
                FirstName       = "李",
                LastName        = "东生",
                ChineseFullName = "李东生",
                MobileNumber    = "13899998888",
                Email           = "*****@*****.**"
            };

            // 这里注意:创建的密码要满足响应的密码规则,否则将无法创建用户。
            success = idManager.CreateUser(newUser, "123@Abc");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser.Id, "Admin");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser.Id, "CanEdit");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser.Id, "User");
            if (!success)
            {
                return(success);
            }

            success = idManager.AddUserToRole(newUser.Id, "CustomerUser");
            if (!success)
            {
                return(success);
            }

            return(success);
        }