Esempio n. 1
0
        public AdminUserInfo TransformUserInfo(AdminUser user)
        {
            var userInfo = new AdminUserInfo();

            userInfo.Id       = user.Id;
            userInfo.Name     = user.Name;
            userInfo.NickName = user.NickName;
            userInfo.Password = user.Password;
            userInfo.Phone    = user.Phone;
            userInfo.RealName = user.RealName;
            userInfo.PwdFlag  = user.PwdFlag;
            userInfo.Type     = user.Type ?? 0;
            userInfo.Roles    = user.UserRoles.Select(ur => new AdminRole
            {
                Id     = ur.RoleId,
                Name   = ur.Role.Name,
                Status = ur.Role.Status
            }).ToList();
            userInfo.Status     = user.Status;
            userInfo.StatusTime = user.StatusTime;
            userInfo.Gender     = user.Gender;
            userInfo.CreateTime = user.CreateTime;
            if (userInfo.Roles != null && userInfo.Roles.Count > 0)
            {
                userInfo.CurrentRole = userInfo.Roles[0];
            }
            return(userInfo);
            //return redis.SetCache(_key_userInfo + user.Id, userInfo, DefaultTimeSpan);
        }
 public IActionResult SelfPassword(AdminUserInfo userInfo)
 {
     //RedisService redis = new RedisService();
     //var userInfo = redis.GetUserInfo(id.ToString());
     ViewBag.User = userInfo;
     return(View());
 }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //   context.Response.Write("Hello World");
            string action = context.Request["action"];

            UserData = context.Session["UserData"] as AdminUserInfo;
            switch (action)
            {
            case "GetList":
                string RoleTypes = context.Request["RoleTypes"];
                context.Response.Write(GetList(RoleTypes));
                context.Response.End();
                break;

            case "GetUser":
                context.Response.Write(GetUser(context));
                context.Response.End();
                break;

            case "geturltest":
                //HttpContext.Current.Request.Url.Authority;
                string url = "http://" + HttpContext.Current.Request.Url.Authority + "/";
                context.Response.Write(url);
                context.Response.End();
                break;
            }
        }
Esempio n. 4
0
        protected async Task <IActionResult> AddNewUser(AdminUserInfo adminUserInfo)
        {
            // ensure there is a ADMINISTRATION_ROLE


            // Ensure a user named [email protected] is an Administrator
            var user = await _userManager.FindByEmailAsync(adminUserInfo.Email);

            IdentityResult results;

            if (user == null)
            {
                user          = new ApplicationUser();
                user.UserName = adminUserInfo.UserName;
                user.Email    = adminUserInfo.Email;
                results       = await _userManager.CreateAsync(user, adminUserInfo.Password);

                if (results.Succeeded)
                {
                    await UpdateUserRole(user, adminUserInfo.Roles);

                    UpdateUserIdCommand updateUserIdCommand = new UpdateUserIdCommand(adminUserInfo.PilotId, user.Id.ToString());
                    int result = await _mediator.Send(updateUserIdCommand);

                    //await _memberService.UpdatePilotUserId(adminUserInfo.PilotId, user.Id.ToString());
                }
            }
            else
            {
            }

            return(Ok());
        }
Esempio n. 5
0
        public ActionResult EditUser(int id = 0)
        {
            var userID = UserID;

            try
            {
                AdminUserInfo userInfo;
                if (id > 0)
                {
                    userInfo = adminUserBLL.GetAdminUserInfo(id);
                }
                else
                {
                    userInfo = new AdminUserInfo();
                }
                var page = new PagingModel()
                {
                    PageIndex = 1, PageSize = int.MaxValue
                };
                var RoleList = adminUserBLL.GetAdminRoleList(page);
                ViewBag.RoleList = RoleList.Items;
                return(View(userInfo));
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(Content(""));
        }
Esempio n. 6
0
        public ActionResult Edit(int id = 0)
        {
            bool isEdit = id > 0;

            if (!isEdit)
            {
            }

            AdminUserInfo userInfo = null;

            if (isEdit)
            {
                userInfo = _adminUserInfoService.GetAdminUserInfo(id);
                if (userInfo == null)
                {
                    return(RenderError("信息不存在!"));
                }
            }
            else
            {
                userInfo = new AdminUserInfo();
            }
            AdminUserInfo_EditVD vd = new AdminUserInfo_EditVD()
            {
                IsEdit        = isEdit,
                AdminUserInfo = userInfo,
            };

            return(View(vd));
        }
Esempio n. 7
0
        public JsonResult SaveUser(AdminUserInfo userinfo)
        {
            var userID = UserID;

            try
            {
                if (userinfo.id == 0 && adminUserBLL.ExistsAdminUserName(userinfo.UserName))
                {
                    return(Json(new { Error = 1, Message = "此賬號已被佔用" }));
                }
                var falg = adminUserBLL.SaveAdminUserInfo(userinfo);
                if (falg)
                {
                    return(Json(new { Error = 0 }));
                }
                else
                {
                    return(Json(new { Error = 1 }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(Json(new { Error = 1, Message = ex.Message }));
            }
        }
Esempio n. 8
0
        private LoginUserModel GetUserPermission(AdminUserInfo userInfo)
        {
            var loginUserModel = new LoginUserModel();

            loginUserModel.AdminUserInfo = userInfo;
            if (userInfo.Status == 1)
            {
                var lstMenuRoot = new List <AdminMenuModel>();
                IList <AdminMenuInfo> lstMenu;
                //获取菜单
                if (userInfo.IsAdmin)
                {
                    lstMenu = adminUserDAL.GetAllMenuPermission();
                }
                else
                {
                    lstMenu = adminUserDAL.GetMenuListByUserID(userInfo.id);
                }
                if (lstMenu != null && lstMenu.Count > 0)
                {
                    //添加主菜单
                    lstMenuRoot.AddRange(lstMenu.Where(root => root.ParentPermission == EnumPermission.None).Select(p => new AdminMenuModel
                    {
                        root = p,
                        //添加子菜单
                        children = lstMenu.Where(child => child.IsShow && child.ParentPermission == p.Permission).ToList()
                    }));
                }
                var lstPermission = lstMenu.Select(p => p.Permission).ToList();
                loginUserModel.MenuList      = lstMenuRoot;
                loginUserModel.PermissionSet = new HashSet <EnumPermission>(lstPermission);
            }
            return(loginUserModel);
        }
Esempio n. 9
0
        public IActionResult UpdateStatus(string activityId, int status, string session)
        {
            try
            {
                //var strjson = httpContext.Request.Query["session"];

                //if (string.IsNullOrEmpty(strjson))
                //{
                //    strjson = httpContext.Request.Form["session"];
                //}
                AdminUserInfo adminUser = null;
                adminUser = VerifySession(session, adminUser, _adminUserInfoService);
                if (adminUser == null)
                {
                    return(Json(new
                    {
                        code = -1,
                        msg = "请先登录",
                        data = new
                        {
                        }
                    }));
                }

                var activity = _activityService.GetObject(x => x.Id == activityId);

                if (activity != null)
                {
                    activity.ScheduleStatus = status;
                    _activityService.SaveObject(activity);

                    return(Json(new
                    {
                        code = 0,
                        msg = "修改状态成功",
                        data = activity
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        code = -1,
                        msg = "该活动不存在",
                        data = new { }
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    code = -1,
                    msg = "服务器异常:" + ex.Message,
                    data = new {
                    }
                }));
            }
        }
Esempio n. 10
0
        public ActionResult Edit([Bind(Prefix = "AdminUserInfo")] AdminUserInfo userInfo_Form, string password)
        {
            bool isEdit = userInfo_Form.Id > 0;

            this.Validator(userInfo_Form.UserName, "用户名", "AdminUserInfo.UserName", false)
            .IsFalse(z => this._adminUserInfoService.CheckUserNameExisted(userInfo_Form.Id, z), "用户名已存在!", true);
            this.Validator(userInfo_Form.RealName, "真实姓名", "AdminUserInfo.RealName", false);
            this.Validator(userInfo_Form.Phone, "电话", "AdminUserInfo.Phone", false);

            if (!isEdit || !password.IsNullOrEmpty())
            {
                this.Validator(password, "密码", "Password", false).MinLength(6);
            }

            if (!ModelState.IsValid)
            {
                AdminUserInfo_EditVD vd = new AdminUserInfo_EditVD()
                {
                    IsEdit        = isEdit,
                    AdminUserInfo = userInfo_Form
                };
                return(View(vd));
            }

            AdminUserInfo userInfo = null;

            if (isEdit)
            {
                userInfo = _adminUserInfoService.GetAdminUserInfo(userInfo_Form.Id);
                if (userInfo == null)
                {
                    return(RenderError("信息不存在!"));
                }
            }
            else
            {
                var passwordSalt = DateTime.Now.Ticks.ToString();
                userInfo = new AdminUserInfo()
                {
                    PasswordSalt  = passwordSalt,
                    LastLoginTime = DateTime.Now,
                    ThisLoginTime = DateTime.Now,
                    AddTime       = DateTime.Now,
                    UpdateTime    = DateTime.Now
                };
            }

            if (!password.IsNullOrEmpty())
            {
                userInfo.Password = this._adminUserInfoService.GetPassword(password, userInfo.PasswordSalt, false);//生成密码
            }

            this.TryUpdateModel(userInfo, "AdminUserInfo", null, new[] { "Id" });
            this._adminUserInfoService.SaveObject(userInfo);

            base.SetMessager(MessageType.success, "{0}成功!".With(isEdit ? "修改" : "新增"));
            return(RedirectToAction("Edit", new { id = userInfo.Id }));
        }
Esempio n. 11
0
 private void BindList()
 {
     IList<AdminUserInfo> list = new AdminUser().GetList(20, 0);
     AdminUserInfo aInfo = new AdminUserInfo();
     aInfo.Time = DateTime.Now;
     list.Add(aInfo);
     gvUserList.DataSource = list;
     gvUserList.DataBind();
 }
Esempio n. 12
0
        public void EditOne(Account_AddEditDTO editOne, string updater)
        {
            using (MiniSenDbContext dbContext = new MiniSenDbContext())
            {
                CommonService <AdminUser> commonService = new CommonService <AdminUser>(dbContext);

                bool isExist = commonService.AnyByIdNoMarkDeleted(editOne.Id);
                if (!isExist)
                {
                    throw new PushToUserException("Current account item is not exist");
                }

                bool hasExist = commonService.WhereNoMarkDeleted().Where(d => 0 == d.DelFlag && d.Account.Equals(editOne.Account) && d.Id != editOne.Id).Any();
                if (hasExist)
                {
                    throw new PushToUserException($"A admin user item with the same account '{editOne.Account}' already exists");
                }

                try
                {
                    dbContext.DBTransaction.Begin();

                    AdminUser updateAdminUserOne = CoffeeMapper <Account_AddEditDTO, AdminUser> .AutoMap(editOne, (_out, _in) =>
                    {
                        _out.Updater    = updater;
                        _out.UpdateTime = DateTime.Now;
                    });

                    var matchAdminUserInfo = dbContext.Queryable <AdminUserInfo>().Select().Where(a => a.AdminUserId.Equals(editOne.Id)).ToList();

                    if (matchAdminUserInfo.Count != 1)
                    {
                        throw new Exception($"TABLE 'IDSBG_ECARD.B_ADMIN_USER' record which AdminUserId = '{editOne.Id}' is not only one or not exist");
                    }

                    AdminUserInfo updateAdminUserInfoOne = matchAdminUserInfo[0];
                    updateAdminUserInfoOne.Name       = editOne.Name;
                    updateAdminUserInfoOne.RemarkInfo = editOne.Remarks;
                    updateAdminUserInfoOne.Updater    = updater;
                    updateAdminUserInfoOne.UpdateTime = DateTime.Now;

                    dbContext.Update <AdminUserInfo>(updateAdminUserInfoOne);
                    dbContext.Update <AdminUser>(a => new { a.Account, a.RemarkInfo, a.Updater, a.UpdateTime }, updateAdminUserOne)
                    .Where(a => a.Id.Equals(editOne.Id)).Done();

                    dbContext.DBTransaction.Commit();
                }
                catch (Exception ex)
                {
                    dbContext.DBTransaction.Rollback();

                    throw ex;
                }
            }
        }
Esempio n. 13
0
        public async Task <IActionResult> CurrentUser()
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            AdminUserInfo adminUserInfo = _mapper.Map <ApplicationUser, AdminUserInfo>((user));

            return(Ok(new OperationResponse <AdminUserInfo> {
                IsSuccess = true, Message = $"{user.Id} has been found", Record = adminUserInfo
            }
                      ));
        }
        public async Task DeleteUser(AdminUserInfo user)
        {
            var stringContent = new StringContent(JsonSerializer.Serialize(user), Encoding.UTF8, "application/json");
            var result        = await _httpClient.PostAsync("api/Administrator/DeleteUser", stringContent);

            if (result.StatusCode == System.Net.HttpStatusCode.BadRequest)
            {
                throw new Exception(await result.Content.ReadAsStringAsync());
            }
            result.EnsureSuccessStatusCode();
        }
Esempio n. 15
0
        /// <summary>
        /// 获取用户列表(所有角色为客服且无分组的)
        /// </summary>
        /// <returns></returns>
        public LoginUserModel GetLoginUserByUserID(int userID)
        {
            LoginUserModel loginUserModel = null;

            AdminUserInfo userInfo = adminUserDAL.GetByUserID(userID);

            if (userInfo != null)
            {
                loginUserModel = GetUserPermission(userInfo);
            }
            return(loginUserModel);
        }
Esempio n. 16
0
        protected async Task EnsureAdmin()
        {
            // ensure there is a ADMINISTRATION_ROLE
            AdminUserInfo adminUserInfo = new AdminUserInfo();

            adminUserInfo.Roles.Add(IdentityInfo.Roles.Administrators.ToString());
            adminUserInfo.UserName = "******";
            adminUserInfo.Email    = "*****@*****.**";
            adminUserInfo.Password = "******";

            await AddNewUser(adminUserInfo);
        }
 public void Insert(AdminUserInfo entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException(nameof(entity));
     }
     using (var db = new BaseDatabaseContext())
     {
         db.AdminUserInfos.Add(entity);
         db.SaveChanges();
     }
 }
Esempio n. 18
0
        void GetGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToLower() == "add")
            {
                GridViewRow row = (e.CommandSource as Control).Parent.Parent as GridViewRow;
                Hashtable   htd = new Hashtable();

                foreach (TemplateField tf in GridViewManager1.GridView.Columns)
                {
                    GenericItem item = tf.FooterTemplate as GenericItem;
                    if (item == null)
                    {
                        continue;
                    }
                    try
                    {
                        foreach (DictionaryEntry de in item.ExtractValues(row))
                        {
                            htd.Add(de.Key, de.Value);
                        }
                    }
                    catch (Exception ex)
                    {
                        Exceptions.Logger.Error(ex);
                        HtmlHelper.Alert(ex.Message, Page);
                        return;
                    }
                }

                try
                {
                    AdminUserController ctrl = new AdminUserController();
                    AdminUserInfo       info = new AdminUserInfo();
                    foreach (System.Reflection.PropertyInfo property in CBO.GetPropertyInfo(typeof(AdminUserInfo)))
                    {
                        if (htd[property.Name] != null)
                        {
                            property.SetValue(info, htd[property.Name], null);
                        }
                    }
                    ctrl.InsertAdminUser(info);
                    GridViewManager1.GridView.PageIndex = GridViewManager1.GridView.PageCount;
                    GridViewManager1.LoadData();
                }
                catch (Exception ex)
                {
                    Exceptions.Logger.Error(ex);
                    HtmlHelper.Alert(ex.Message, Page);
                }
            }
        }
Esempio n. 19
0
        public async Task <IActionResult> Edit(AdminUserInfo_EditVD model)
        {
            bool isEdit = model.Id > 0;

            this.Validator(model.UserName, "用户名", "UserName", false)
            .IsFalse(z => this._adminUserInfoService.CheckUserNameExisted(model.Id, z), "用户名已存在!", true);

            if (!isEdit || !model.Password.IsNullOrEmpty())
            {
                this.Validator(model.Password, "密码", "Password", false).MinLength(6);
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            AdminUserInfo userInfo = null;

            if (isEdit)
            {
                userInfo = _adminUserInfoService.GetAdminUserInfo(model.Id);
                if (userInfo == null)
                {
                    return(RenderError("信息不存在!"));
                }
            }
            else
            {
                var passwordSalt = DateTime.Now.Ticks.ToString();
                userInfo = new AdminUserInfo()
                {
                    PasswordSalt  = passwordSalt,
                    LastLoginTime = DateTime.Now,
                    ThisLoginTime = DateTime.Now,
                    AddTime       = DateTime.Now,
                };
            }

            if (!model.Password.IsNullOrEmpty())
            {
                userInfo.Password = this._adminUserInfoService.GetPassword(model.Password, userInfo.PasswordSalt, false);//生成密码
            }

            await this.TryUpdateModelAsync(userInfo, "", z => z.Note, z => z.UserName);

            this._adminUserInfoService.SaveObject(userInfo);

            base.SetMessager(MessageType.success, $"{(isEdit ? "修改" : "新增")}成功!");
            return(RedirectToAction("Index"));
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //   context.Response.Write("Hello World");
            string action = context.Request["action"];

            UserData = context.Session["UserData"] as AdminUserInfo;
            switch (action)
            {
            case "GetList":
                string RoleTypes = context.Request["RoleTypes"];
                context.Response.Write(GetList(RoleTypes));
                context.Response.End();
                break;
            }
        }
Esempio n. 21
0
        static void CreateTestData_User()
        {
            Repository <AdminUserInfo> repository = new Repository <AdminUserInfo>();
            AdminUserInfo adminUser = new AdminUserInfo()
            {
                Mobile     = "15577778888",
                Email      = "*****@*****.**",
                Password   = Banana.Utility.Encryption.MD5.Encrypt("mimashi123"),
                UserName   = "******",
                RealName   = "Lio.Huang",
                IsDisable  = EYesOrNo.No,
                CreateTime = DateTime.Now
            };

            repository.Insert(adminUser);
        }
Esempio n. 22
0
        public string AddNewOne(Account_AddEditDTO addOne, string creater)
        {
            using (MiniSenDbContext dbContext = new MiniSenDbContext())
            {
                CommonService <AdminUser>     commonAdminUserService     = new CommonService <AdminUser>(dbContext);
                CommonService <AdminUserInfo> commonAdminUserInfoService = new CommonService <AdminUserInfo>(dbContext);

                bool hasExist = commonAdminUserService.WhereNoMarkDeleted().Where(d => 0 == d.DelFlag && d.Account.Equals(addOne.Account)).Any();
                if (hasExist)
                {
                    throw new PushToUserException($"A admin user item with the same account '{addOne.Account}' already exists");
                }

                try
                {
                    dbContext.DBTransaction.Begin();

                    AdminUser newAdminUserOne = CoffeeMapper <Account_AddEditDTO, AdminUser> .AutoMap(addOne, (_out, _in) =>
                    {
                        _out.PasswordHash = "ensky123.";  //系統默認密碼
                        _out.Id           = Utils.GetGuidStr();
                        _out.Creater      = creater;
                    });

                    string accountId = commonAdminUserService.Insert(newAdminUserOne);

                    AdminUserInfo newAdminUserInfoOne = CoffeeMapper <Account_AddEditDTO, AdminUserInfo> .AutoMap(addOne, (_out, _in) =>
                    {
                        _out.Id          = Utils.GetGuidStr();
                        _out.Creater     = creater;
                        _out.AdminUserId = accountId;
                    });

                    commonAdminUserInfoService.Insert(newAdminUserInfoOne);

                    dbContext.DBTransaction.Commit();

                    return(accountId);
                }
                catch (Exception ex)
                {
                    dbContext.DBTransaction.Rollback();

                    throw ex;
                }
            }
        }
Esempio n. 23
0
        public async Task <IActionResult> SaveUser(AdminUserInfo adminUserInfo)
        {
            var user = await _userManager.FindByIdAsync(adminUserInfo.Id);

            if (user != null)
            {
                IdentityResult identityResult = await _userManager.UpdateAsync(user);

                if (!identityResult.Succeeded)
                {
                    var error = identityResult.Errors.FirstOrDefault().Description;
                    return(StatusCode(10000));
                }
                return(Ok());
            }
            return(StatusCode(10001));
        }
Esempio n. 24
0
        protected AdminUserInfo VerifySession(string session, AdminUserInfo adminUser, AdminUserInfoService _adminUserInfoService)
        {
            var result = _encryptionService.CommonDecrypt(session);

            if (!string.IsNullOrEmpty(result))
            {
                var arr = result.Split("-");
                if (arr.Length == 3)
                {
                    adminUser = _adminUserInfoService.GetUserInfo(arr[0]);
                }
                else
                {
                }
            }

            return(adminUser);
        }
Esempio n. 25
0
        /// <summary>
        /// 使用账号和密码登录
        /// </summary>
        /// <returns></returns>
        public LoginUserModel GetLoginUserByLogin(string userName, string password)
        {
            LoginUserModel loginUserModel = null;

            AdminUserInfo userInfo = adminUserDAL.GetByPassword(userName, MD5Hash.GetMd5String(password));

            if (userInfo != null)
            {
                if (userInfo.Status == 1)
                {
                    var loginTime = DateTime.Now;
                    userInfo.LastLoginTime = loginTime;
                    adminUserDAL.UpdateUserLastLoginTime(userInfo.id, loginTime);
                }
                loginUserModel = GetUserPermission(userInfo);
            }

            return(loginUserModel);
        }
Esempio n. 26
0
        public async Task <IActionResult> DeleteUser(AdminUserInfo adminUserInfo)
        {
            var user = await _userManager.FindByIdAsync(adminUserInfo.Id);

            if (user != null)
            {
                IdentityResult identityResult = await _userManager.DeleteAsync(user);

                if (!identityResult.Succeeded)
                {
                    var error = identityResult.Errors.FirstOrDefault().Description;
                    return(StatusCode(10000));
                }
                DeleteUserIdCommand deleteUserIdCommand = new DeleteUserIdCommand(adminUserInfo.PilotId, user.Id.ToString());
                int result = await _mediator.Send(deleteUserIdCommand);

                return(result >= 0 ? Ok() : StatusCode(10003));
            }
            return(StatusCode(10001));
        }
        /// <summary>
        /// 返回店铺给下拉控件
        /// </summary>
        /// <returns></returns>
        public string GetShop(HttpContext context)
        {
            List <TS_Shop> AllList = new List <TS_Shop>();

            if (context.Session["UserData"] != null)
            {
                AdminUserInfo UserData = context.Session["UserData"] as AdminUserInfo;
                if (UserData.UserTypes != UserType.admin)//不是管理员只能返回自己添加的
                {
                    var sql = TS_ShopSet.SelectAll().Where(TS_ShopSet.CreateManId.Equal(UserData.Id));
                    AllList = OPBiz.GetOwnList <TS_Shop>(sql);
                }
                else
                {
                    var sql = TS_ShopSet.SelectAll();
                    AllList = OPBiz.GetOwnList <TS_Shop>(sql);
                }
            }
            return(JsonHelper.ToJson(AllList, true));
        }
Esempio n. 28
0
        private static async Task CreateAdminUserIfNotExistsAsync(
            UserManager <ApplicationUser> userManager,
            AdminUserInfo userInfo)
        {
            var user = await userManager.FindByNameAsync(userInfo.Email);

            if (user == null)
            {
                user = new ApplicationUser(userInfo.Id, userInfo.Email)
                {
                    ActivationTimeUtc = DateTime.Now,
                    Active            = true,
                    ExpiryDateUtc     = DateTime.Now.AddYears(10),
                };
                var result = await userManager.CreateAsync(user, userInfo.Password);

                if (!result.Succeeded)
                {
                    throw new InvalidOperationException(result.Errors.First().Description);
                }

                var claims = new[]
                {
                    new Claim(JwtClaimTypes.Name, $"{userInfo.FirstName} {userInfo.LastName}"),
                    new Claim(JwtClaimTypes.GivenName, userInfo.FirstName),
                    new Claim(JwtClaimTypes.FamilyName, userInfo.LastName),
                    new Claim(JwtClaimTypes.Email, userInfo.Email),
                    new Claim(JwtClaimTypes.EmailVerified, "true", ClaimValueTypes.Boolean),
                };
                result = await userManager.AddClaimsAsync(user, claims);

                await userManager.AddToRoleAsync(user, Roles.Admin);

                if (!result.Succeeded)
                {
                    throw new InvalidOperationException(result.Errors.First().Description);
                }
            }
        }
Esempio n. 29
0
        public ActionResult Index()
        {
            var systemConfig = _systemConfigService.GetObject(z => true);

            if (systemConfig != null)
            {
                return(Content("已经进行过初始化!"));
            }

            var salt     = DateTime.Now.Ticks.ToString();
            var password = "******";

            var adminUserInfo = new AdminUserInfo()
            {
                UserName      = "******",
                PasswordSalt  = salt,
                Password      = _adminUserInfoService.GetPassword(password, salt, false),
                RealName      = "",
                LastLoginTime = DateTime.Now,
                ThisLoginTime = DateTime.Now,
                LastLoginIP   = "",
                ThisLoginIP   = "",
                Phone         = "",
                AddTime       = DateTime.Now,
                UpdateTime    = DateTime.Now
            };

            _adminUserInfoService.SaveObject(adminUserInfo);

            systemConfig = new SystemConfig()
            {
                Id         = 1,
                SystemName = "AzureDemo",
            };
            _systemConfigService.SaveObject(systemConfig);

            return(Content("OK"));
        }
Esempio n. 30
0
        public async Task <IActionResult> EditUser(AdminUserInfo adminUserInfo)
        {
            var user = await _userManager.FindByIdAsync(adminUserInfo.Id);

            if (user != null)
            {
                if (!string.IsNullOrEmpty(adminUserInfo.Password))
                {
                    user.PasswordHash = _passwordHasher.HashPassword(user, adminUserInfo.Password);
                }
                if (!string.IsNullOrEmpty(adminUserInfo.Email))
                {
                    user.Email = adminUserInfo.Email;
                }
                if (!string.IsNullOrEmpty(adminUserInfo.Email))
                {
                    IdentityResult identityResult = await _userManager.UpdateAsync(user);

                    if (!identityResult.Succeeded)
                    {
                        var error = identityResult.Errors.FirstOrDefault().Description;
                        return(StatusCode(10000));
                    }
                    await UpdateUserRole(user, adminUserInfo.Roles);

                    UpdateUserIdCommand updateUserIdCommand = new UpdateUserIdCommand(adminUserInfo.PilotId, user.Id.ToString());
                    int result = await _mediator.Send(updateUserIdCommand);

                    //await _memberService.UpdatePilotUserId(adminUserInfo.PilotId, user.Id.ToString());

                    return(result >= 0 ? Ok(): StatusCode(10003));
                }
                return(StatusCode(10002));
            }
            return(StatusCode(10001));
        }
Esempio n. 31
0
        //[ValidateAntiForgeryToken] 安全必须 外网出错 所需的防伪 Cookie“__RequestVerificationToken”不存在。 暂时去掉,待解决
        public ActionResult Index(LoginModel mode)
        {
            // if (ModelState.IsValid)

            ViewData["UserType"] = GenerateList();
            //if (Session["ValidateCode"] != null)
            //{
            #region  获取cookies
            //if (!string.IsNullOrEmpty(Request.Cookies["UserData"]["AdminUserInfo"]))//Cookies保存 获取解析
            //{
            //    string dataj = Request.Cookies["UserData"]["AdminUserInfo"];
            //    UserData = JsonHelper.FromJson<AdminUserInfo>(dataj);
            //    if (UserData != null)
            //    {
            //        return RedirectToAction("index", "home");
            //    }
            //}
            #endregion

            string Vcode = Session["ValidateCode"].ToString();
            if (mode.VCode != null && mode.VCode.Trim().Equals(Vcode))//验证码
            {
                UserData = null;
                List <V_UserRole> adminRole = null;
                bool IsHaveP = false; //是否有权限登录
                mode.UserType = "1";  //
                #region  根据类型登录
                switch (mode.UserType)
                {
                case "1"://账号密码登录
                    var sql = V_UserRoleSet.SelectAll().Where(V_UserRoleSet.LoginName.Equal(mode.LoginName).And(V_UserRoleSet.Password.Equal(mode.Password)));
                    adminRole = URBiz.GetOwnList <V_UserRole>(sql);
                    break;

                case "0"://姓名登录
                    var sql0 = V_UserRoleSet.SelectAll().Where(V_UserRoleSet.LoginName.Equal(mode.LoginName).And(V_UserRoleSet.UserType.Equal(0)));
                    adminRole = URBiz.GetOwnList <V_UserRole>(sql0);
                    if (adminRole != null && adminRole.Count > 0)//检查是否存在,不存在就添加,给登录用户的角色
                    {
                        break;
                    }
                    else
                    {
                        RMS_User item = new RMS_User();
                        item.Id         = Guid.NewGuid();
                        item.LoginName  = mode.LoginName;
                        item.UserType   = 0;
                        item.CreateTime = DateTime.Now;
                        item.ModifyTime = DateTime.Now;
                        uBiz.Add(item);

                        List <RMS_Role> listRole = URBiz.GetOwnList <RMS_Role>(RMS_RoleSet.SelectAll().Where(RMS_RoleSet.RoleTypes.Equal(0)));//所有的姓名登录角色

                        RMS_UserRole urItem = new RMS_UserRole();
                        urItem.Id     = Guid.NewGuid();
                        urItem.UserId = item.Id;
                        urItem.RoleId = listRole[0].Id;
                        urBiz.Add(urItem);

                        adminRole = URBiz.GetOwnList <V_UserRole>(sql0);
                    }



                    break;

                case "2"://身份证登录
                    var sql2 = V_UserRoleSet.SelectAll().Where(V_UserRoleSet.LoginName.Equal(mode.LoginName).And(V_UserRoleSet.UserType.Equal(2)));
                    adminRole = URBiz.GetOwnList <V_UserRole>(sql2);
                    if (adminRole != null && adminRole.Count > 0)//检查是否存在,不存在就添加,给身份证用户的角色
                    {
                        break;
                    }
                    else
                    {
                        RMS_User item = new RMS_User();
                        item.Id         = Guid.NewGuid();
                        item.LoginName  = mode.LoginName;
                        item.UserType   = 2;
                        item.CreateTime = DateTime.Now;
                        item.ModifyTime = DateTime.Now;
                        uBiz.Add(item);

                        List <RMS_Role> listRole = URBiz.GetOwnList <RMS_Role>(RMS_RoleSet.SelectAll().Where(RMS_RoleSet.RoleTypes.Equal(2)));//所有的姓名登录角色

                        RMS_UserRole urItem = new RMS_UserRole();
                        urItem.Id     = Guid.NewGuid();
                        urItem.UserId = item.Id;
                        urItem.RoleId = listRole[0].Id;
                        urBiz.Add(urItem);

                        adminRole = URBiz.GetOwnList <V_UserRole>(sql2);
                    }
                    break;

                default:

                    break;
                }

                #endregion

                if ((adminRole != null && adminRole.Count > 0)) // 账号是否存在,添加权限配置
                {
                    #region 存用户数据

                    UserData           = new AdminUserInfo();
                    UserData.UserTypes = int.Parse(adminRole[0].UserType.ToString());
                    // UserData.adminUserInfo = adminRole[0];
                    UserData.Id       = adminRole[0].Id;
                    UserData.UserName = adminRole[0].LoginName;
                    UserData.RoleId   = adminRole[0].RoleId;
                    UserData.Password = adminRole[0].Password;

                    if (adminRole[0].DepartmentId != null)
                    {
                        var            dpsql  = RMS_DepartmentSet.SelectAll().Where(RMS_DepartmentSet.Id.Equal(adminRole[0].DepartmentId));
                        RMS_Department dpItem = dpBiz.GetEntity(dpsql);
                        if (dpItem != null)
                        {
                            UserData.DepartmentId   = dpItem.Id;
                            UserData.DepartmentName = dpItem.Name;
                        }
                    }
                    IsHaveP = true;

                    #endregion

                    #region  获取权限
                    if (IsHaveP)                                                                                                                                                                //可以登录
                    {
                        List <V_RoleManus>       manus      = URBiz.GetOwnList <V_RoleManus>(V_RoleManusSet.SelectAll().Where(V_RoleManusSet.RoleId.Equal(UserData.RoleId)));                   //所有的菜单
                        List <V_RoleManuButtons> buttons    = URBiz.GetOwnList <V_RoleManuButtons>(V_RoleManuButtonsSet.SelectAll().Where(V_RoleManuButtonsSet.RoleId.Equal(UserData.RoleId))); //角色拥有的菜单的所有按钮
                        List <V_MenuButtons>     AllButtons = URBiz.GetOwnList <V_MenuButtons>(V_MenuButtonsSet.SelectAll());                                                                   //所有菜单的所有按钮
                        List <Manu> ListManus = new List <Manu>();
                        if (manus != null && manus.Count > 0)
                        {
                            foreach (V_RoleManus item in manus)
                            {
                                Manu OneManu = new Manu();
                                OneManu.manuInfo      = item;
                                OneManu.ListButtons   = buttons.FindAll(p => p.ManuId.Equals(item.ManuId)).OrderBy(p => p.OrderNo).ToList();
                                OneManu.ManuAllButton = AllButtons.FindAll(p => p.ManuId.Equals(item.ManuId));
                                ListManus.Add(OneManu);
                            }
                            UserData.ListManus = ListManus;
                        }

                        #region   存cookies
                        //string datajson = JsonHelper.ToJson(UserData);
                        //HttpCookie cookie = new HttpCookie("UserData");//初使化并设置Cookie的名称
                        //DateTime dt = DateTime.Now;
                        //TimeSpan ts = new TimeSpan(0, 1, 0, 0, 0);//过期时间为1分钟
                        //cookie.Expires = dt.Add(ts);//设置过期时间

                        //cookie.Values.Add("AdminUserInfo", datajson);
                        //Response.AppendCookie(cookie);

                        #endregion


                        return(RedirectToAction("index", "home"));
                    }

                    #endregion
                }
                else
                {
                    //  return RedirectToAction("index", "Login");
                    // 如果我们进行到这一步时某个地方出错,则重新显示表单
                    ViewData["IsShowAlert"] = true;
                    ViewData["Alert"]       = "账号或者密码有误";
                }
            }
            else
            {
                ViewData["IsShowAlert"] = true;
                ViewData["Alert"]       = "验证码有误";
            }
            return(View());
        }
Esempio n. 32
0
        /// <summary>
        /// Creates the or update admin user.
        /// </summary>
        /// <param name="userInfo">The user information.</param>
        /// <returns>System.Nullable&lt;Guid&gt;.</returns>
        public Guid? CreateOrUpdateAdminUser(AdminUserInfo userInfo)
        {
            try
            {
                userInfo.CheckNullObject("userInfo");

                using (var controller = new AdminUserInfoAccessController())
                {
                    return controller.CreateOrUpdateAdminUserInfo(userInfo, ContextHelper.GetCurrentOperatorKey());
                }
            }
            catch (Exception ex)
            {
                throw ex.Handle( userInfo);
            }
        }