public CustomJsonResult Edit(string operater, RopMerchMasterEdit rop)
        {
            CustomJsonResult result = new CustomJsonResult();


            using (TransactionScope ts = new TransactionScope())
            {
                var user = CurrentDb.SysMerchUser.Where(m => m.Id == rop.Id).FirstOrDefault();

                if (!string.IsNullOrEmpty(rop.Password))
                {
                    user.PasswordHash = PassWordHelper.HashPassword(rop.Password);
                }

                user.FullName    = rop.FullName;
                user.Email       = rop.Email;
                user.PhoneNumber = rop.PhoneNumber;
                user.IsDisable   = rop.IsDisable;
                user.MendTime    = DateTime.Now;
                user.Mender      = operater;

                CurrentDb.SaveChanges();
                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "保存成功");
            }


            return(result);
        }
Beispiel #2
0
        public CustomJsonResult Edit(string operater, string agentId, RopUserEdit rop)
        {
            CustomJsonResult result = new CustomJsonResult();


            using (TransactionScope ts = new TransactionScope())
            {
                var agentUser = CurrentDb.SysAgentUser.Where(m => m.Id == rop.Id).FirstOrDefault();

                if (!string.IsNullOrEmpty(rop.Password))
                {
                    agentUser.PasswordHash = PassWordHelper.HashPassword(rop.Password);
                }

                agentUser.FullName    = rop.FullName;
                agentUser.Email       = rop.Email;
                agentUser.PhoneNumber = rop.PhoneNumber;
                agentUser.IsDisable   = rop.IsDisable;
                agentUser.MendTime    = DateTime.Now;
                agentUser.Mender      = operater;

                if (string.IsNullOrEmpty(agentUser.YbInsureSign))
                {
                    agentUser.YbInsureSign = YbInsUtil.GetSign(agentUser.Id, agentUser.Id, agentUser.PhoneNumber, agentUser.FullName);
                }

                CurrentDb.SaveChanges();
                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "保存成功");
            }


            return(result);
        }
Beispiel #3
0
        public CustomJsonResult LoginByAccount(RopOwnLoginByAccount rop)
        {
            var result = new CustomJsonResult();
            var ret    = new RetOwnLoginByUrlParams();

            var agentUser = CurrentDb.SysAgentUser.Where(m => m.UserName == rop.UserName).FirstOrDefault();

            if (agentUser == null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "账号不存在"));
            }

            if (!PassWordHelper.VerifyHashedPassword(agentUser.PasswordHash, rop.Password))
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "账号密码不正确"));
            }

            if (agentUser.IsDisable)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "该账号已被禁用"));
            }

            ret.MId = agentUser.AgentId;
            ret.UId = agentUser.Id;

            result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "获取成功", ret);

            return(result);
        }
Beispiel #4
0
        public async Task <int> UpdatePassWord(int?id, string oldpassword, string newpassword)
        {
            if (!IsSafe())
            {
                return(301);//恶意修改
            }
            if (id == null)
            {
                return(302);//查无此人
            }

            var admin = await _context.Admin.FindAsync(id);

            if (admin == null)
            {
                return(302);//查无此人
            }

            string database_old_password = admin.PassWord;
            string para_old_password     = PassWordHelper.Md532Salt(oldpassword, admin.LoginAccount);

            if (database_old_password != para_old_password)
            {
                return(303);//旧密码错误
            }
            string md5_salt_new_password = PassWordHelper.Md532Salt(newpassword, admin.LoginAccount);

            admin.PassWord = md5_salt_new_password;
            _context.Update(admin);
            await _context.SaveChangesAsync();

            RemoveSession();
            return(310);//修改成功
        }
Beispiel #5
0
        public CustomJsonResult LoginByAccount(RopOwnLoginByAccount rop)
        {
            var result = new CustomJsonResult();
            var ret    = new RetOwnLoginByAccount();

            var sysUser = CurrentDb.SysUser.Where(m => m.UserName == rop.UserName).FirstOrDefault();

            if (sysUser == null)
            {
                LoginLog("", "", Enumeration.LoginResult.Failure, rop.LoginWay, rop.Ip, "", "登录失败,账号不存在");
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "登录失败,账号不存在"));
            }

            if (!PassWordHelper.VerifyHashedPassword(sysUser.PasswordHash, rop.Password))
            {
                LoginLog(sysUser.Id, sysUser.Id, Enumeration.LoginResult.Failure, rop.LoginWay, rop.Ip, "", "登录失败,密码不正确");
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "登录失败,密码不正确"));
            }

            if (sysUser.IsDisable)
            {
                LoginLog(sysUser.Id, sysUser.Id, Enumeration.LoginResult.Failure, rop.LoginWay, rop.Ip, "", "登录失败,账号已被禁用");
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "登录失败,账号已被禁用"));
            }

            ret.Token = GuidUtil.New();

            var tokenInfo = new TokenInfo();

            tokenInfo.UserId = sysUser.Id;

            switch (sysUser.BelongSite)
            {
            case Enumeration.BelongSite.Agent:
                var agentUser = CurrentDb.SysAgentUser.Where(m => m.Id == sysUser.Id).FirstOrDefault();
                if (agentUser != null)
                {
                    tokenInfo.AgentId = agentUser.AgentId;
                }
                break;

            case Enumeration.BelongSite.Merch:
                var merchUser = CurrentDb.SysMerchUser.Where(m => m.Id == sysUser.Id).FirstOrDefault();
                if (merchUser != null)
                {
                    tokenInfo.MerchId = merchUser.MerchId;
                }
                break;
            }


            LoginLog(sysUser.Id, sysUser.Id, Enumeration.LoginResult.Success, rop.LoginWay, rop.Ip, "", "登录成功");

            SSOUtil.SetTokenInfo(ret.Token, tokenInfo, new TimeSpan(1, 0, 0));

            result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "登录成功", ret);

            return(result);
        }
        // GET: OrdersController/Create
        public ActionResult Create()
        {
            prepaidCard prepaidCard = new prepaidCard()
            {
                CardCode  = PassWordHelper.GenerateCheckCode(8),
                SecretKey = PassWordHelper.GenerateCheckCode(8)
            };

            return(View(prepaidCard));
        }
Beispiel #7
0
        public CustomJsonResult Add(string operater, string agentId, RopUserAdd rop)
        {
            var result = new CustomJsonResult();

            if (string.IsNullOrEmpty(rop.UserName))
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "用户名不能为空"));
            }

            if (string.IsNullOrEmpty(rop.Password))
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "密码不能为空"));
            }

            var isExistUserName = CurrentDb.SysUser.Where(m => m.UserName == rop.UserName).FirstOrDefault();

            if (isExistUserName != null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, string.Format("该用户名({0})已被使用", rop.UserName)));
            }



            using (TransactionScope ts = new TransactionScope())
            {
                var pAgentUser = CurrentDb.SysAgentUser.Where(m => m.Id == operater).FirstOrDefault();

                var agentUser = new SysAgentUser();
                agentUser.Id            = GuidUtil.New();
                agentUser.PId           = pAgentUser.Id;
                agentUser.UserName      = rop.UserName;
                agentUser.FullName      = rop.FullName;
                agentUser.PasswordHash  = PassWordHelper.HashPassword(rop.Password);
                agentUser.Email         = rop.Email;
                agentUser.PhoneNumber   = rop.PhoneNumber;
                agentUser.BelongSite    = Enumeration.BelongSite.Agent;
                agentUser.IsDelete      = false;
                agentUser.IsDisable     = false;
                agentUser.IsMaster      = false;
                agentUser.AgentId       = pAgentUser.AgentId;
                agentUser.Depth         = pAgentUser.Depth + 1;
                agentUser.Creator       = operater;
                agentUser.CreateTime    = DateTime.Now;
                agentUser.RegisterTime  = DateTime.Now;
                agentUser.SecurityStamp = Guid.NewGuid().ToString().Replace("-", "");
                agentUser.YbInsureSign  = YbInsUtil.GetSign(agentUser.Id, agentUser.Id, agentUser.PhoneNumber, agentUser.FullName);
                CurrentDb.SysAgentUser.Add(agentUser);
                CurrentDb.SaveChanges();
                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "新建成功");
            }

            return(result);
        }
Beispiel #8
0
        // GET: prepaidCards/Create
        public IActionResult Create()
        {
            CardCreateViewModel createViewModel = new CardCreateViewModel()
            {
                CardCode   = PassWordHelper.GenerateCheckCode(8),
                CarsSecret = PassWordHelper.GenerateCheckCode(8)
            };


            return(View(createViewModel));
        }
Beispiel #9
0
        public CustomJsonResult Edit(string pOperater, RopSysStaffUserEdit rop)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {
                var sysStaffUser = CurrentDb.SysStaffUser.Where(m => m.Id == rop.UserId).FirstOrDefault();
                if (!string.IsNullOrEmpty(rop.Password))
                {
                    sysStaffUser.PasswordHash = PassWordHelper.HashPassword(rop.Password);
                }
                sysStaffUser.FullName    = rop.FullName;
                sysStaffUser.Email       = rop.Email;
                sysStaffUser.PhoneNumber = rop.PhoneNumber;
                sysStaffUser.MendTime    = DateTime.Now;
                sysStaffUser.Mender      = pOperater;
                CurrentDb.SaveChanges();


                List <SysUserRole> userRoleList = CurrentDb.SysUserRole.Where(m => m.UserId == rop.UserId).ToList();

                foreach (var userRole in userRoleList)
                {
                    if (!userRole.IsCanDelete)
                    {
                        var role = CurrentDb.SysRole.Where(m => m.Id == userRole.Id).FirstOrDefault();
                        return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, string.Format("不能去掉用户({0})的角色({1})", sysStaffUser.UserName, role.Name)));
                    }

                    CurrentDb.SysUserRole.Remove(userRole);
                }

                if (rop.RoleIds != null)
                {
                    if (rop.RoleIds.Length > 0)
                    {
                        foreach (string roleId in rop.RoleIds)
                        {
                            CurrentDb.SysUserRole.Add(new SysUserRole {
                                Id = GuidUtil.New(), UserId = rop.UserId, RoleId = roleId, Creator = pOperater, CreateTime = DateTime.Now, IsCanDelete = true
                            });
                        }
                    }
                }


                result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "保存成功");

                CurrentDb.SaveChanges();
                ts.Complete();
            }
            return(result);
        }
Beispiel #10
0
        public CustomJsonResult Edit(string operater, RopMerchMasterEdit rop)
        {
            CustomJsonResult result = new CustomJsonResult();


            using (TransactionScope ts = new TransactionScope())
            {
                var user = CurrentDb.SysMerchUser.Where(m => m.Id == rop.UserId).FirstOrDefault();

                if (!string.IsNullOrEmpty(rop.Password))
                {
                    user.PasswordHash = PassWordHelper.HashPassword(rop.Password);
                }

                user.FullName    = rop.FullName;
                user.Email       = rop.Email;
                user.PhoneNumber = rop.PhoneNumber;
                user.IsDisable   = rop.IsDisable;
                user.MendTime    = DateTime.Now;
                user.Mender      = operater;


                var sysUserRoles = CurrentDb.SysUserRole.Where(r => r.UserId == rop.UserId).ToList();

                foreach (var sysUserRole in sysUserRoles)
                {
                    CurrentDb.SysUserRole.Remove(sysUserRole);
                }


                if (rop.RoleIds != null)
                {
                    foreach (var roleId in rop.RoleIds)
                    {
                        if (!string.IsNullOrEmpty(roleId))
                        {
                            CurrentDb.SysUserRole.Add(new SysUserRole {
                                Id = GuidUtil.New(), RoleId = roleId, UserId = rop.UserId, Creator = operater, CreateTime = DateTime.Now
                            });
                        }
                    }
                }

                CurrentDb.SaveChanges();
                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "保存成功");
            }


            return(result);
        }
Beispiel #11
0
        public CustomJsonResult LoginByUrlParams(string mId, string tppId)
        {
            var result = new CustomJsonResult();
            var ret    = new RetOwnLoginByUrlParams();


            if (string.IsNullOrEmpty(mId))
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "您好,应用无法访问,造成的原因:商户标识参数为空"));
            }

            if (string.IsNullOrEmpty(tppId))
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "您好,应用无法访问,造成的原因:用户标识参数为空"));
            }

            var agent = CurrentDb.Agent.Where(m => m.Id == mId).FirstOrDefault();

            if (agent == null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "您好,应用无法访问,造成的原因:商户信息无法解释"));
            }


            var agentUser = CurrentDb.SysAgentUser.Where(m => m.AgentId == mId && m.TppId == tppId).FirstOrDefault();

            if (agentUser == null)
            {
                agentUser               = new SysAgentUser();
                agentUser.Id            = GuidUtil.New();
                agentUser.UserName      = GuidUtil.New();
                agentUser.PasswordHash  = PassWordHelper.HashPassword("Caskujn");
                agentUser.SecurityStamp = GuidUtil.New();
                agentUser.RegisterTime  = DateTime.Now;
                agentUser.IsDisable     = false;
                agentUser.BelongSite    = Enumeration.BelongSite.Agent;
                agentUser.CreateTime    = DateTime.Now;
                agentUser.Creator       = agentUser.Id;
                agentUser.AgentId       = agent.Id;
                agentUser.TppId         = tppId;
                CurrentDb.SysAgentUser.Add(agentUser);
                CurrentDb.SaveChanges();
            }

            ret.MId = agentUser.AgentId;
            ret.UId = agentUser.Id;

            result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "", ret);

            return(result);
        }
        public LoginResult SignIn(string userName, string password, DateTime loginTime, string loginIp)
        {
            LoginResult result = new LoginResult();

            userName = userName.Trim();
            var user = _db.SysUser.Where(m => m.UserName == userName).FirstOrDefault();

            if (user == null)
            {
                result = new LoginResult(Enumeration.LoginResult.Failure, Enumeration.LoginResultTip.UserNotExist);
            }

            else
            {
                var lastUserInfo = CloneObject(user) as SysUser;

                bool isFlag = PassWordHelper.VerifyHashedPassword(user.PasswordHash, password);

                if (!isFlag)
                {
                    result = new LoginResult(Enumeration.LoginResult.Failure, Enumeration.LoginResultTip.UserPasswordIncorrect, lastUserInfo);
                }
                else
                {
                    if (user.Status == Enumeration.UserStatus.Disable)
                    {
                        result = new LoginResult(Enumeration.LoginResult.Failure, Enumeration.LoginResultTip.UserDisabled, lastUserInfo);
                    }
                    else
                    {
                        if (user.IsDelete)
                        {
                            result = new LoginResult(Enumeration.LoginResult.Failure, Enumeration.LoginResultTip.UserDeleted, lastUserInfo);
                        }
                        else
                        {
                            user.LastLoginTime = loginTime;
                            user.LastLoginIp   = loginIp;
                            _db.SaveChanges();

                            result = new LoginResult(Enumeration.LoginResult.Success, Enumeration.LoginResultTip.VerifyPass, lastUserInfo);
                        }
                    }
                }
            }


            return(result);
        }
        public CustomJsonResult Add(AddViewModel model)
        {
            SysAgentUser user = new SysAgentUser();

            user.UserName     = string.Format("AG{0}", model.SysAgentUser.UserName);
            user.FullName     = model.SysAgentUser.FullName;
            user.PasswordHash = PassWordHelper.HashPassword("888888");
            user.Email        = model.SysAgentUser.Email;
            user.PhoneNumber  = model.SysAgentUser.PhoneNumber;
            user.IsDelete     = false;
            user.Status       = Enumeration.UserStatus.Normal;
            user.Type         = Enumeration.UserType.Agent;
            user.WechatNumber = model.SysAgentUser.WechatNumber;
            return(SysFactory.AuthorizeRelay.CreateUser <SysAgentUser>(this.CurrentUserId, user));
        }
Beispiel #14
0
        // GET: Admins/Create
        public IActionResult Create()
        {
            if (PassWordHelper.Md532Salt(GetSession("admin_id") + GetSession("username") + GetSession("permission"), GetSession("account")) != GetSession("token"))
            {
                return(RedirectToAction("Login", "Admins"));
            }
            AdminViewModel adminViewModel = new AdminViewModel()
            {
                AdminName = GetSession("username"),
                AdminId   = Convert.ToInt32(GetSession("admin_id")),
                Password  = PassWordHelper.GenerateCheckCode(8)
            };

            return(View(adminViewModel));
        }
Beispiel #15
0
        public CustomJsonResult Add(AddViewModel model)
        {
            var user = new SysStaffUser();

            user.UserName     = string.Format("HYL{0}", model.SysStaffUser.UserName);
            user.FullName     = model.SysStaffUser.FullName;
            user.PasswordHash = PassWordHelper.HashPassword(model.SysStaffUser.Password);
            user.Email        = model.SysStaffUser.Email;
            user.PhoneNumber  = model.SysStaffUser.PhoneNumber;
            user.Type         = Enumeration.UserType.Staff;
            user.IsDelete     = false;
            user.Status       = Enumeration.UserStatus.Normal;
            int[] userRoleIds = model.UserRoleIds;

            return(SysFactory.AuthorizeRelay.CreateUser <SysStaffUser>(this.CurrentUserId, user, userRoleIds));
        }
Beispiel #16
0
        public APIResponse Login(LoginModel model)
        {
            var clientUser = CurrentDb.SysClientUser.Where(m => m.UserName == model.UserName).FirstOrDefault();

            if (clientUser == null)
            {
                return(ResponseResult(ResultType.Failure, ResultCode.FailureSignIn, "登录失败,用户名不存在"));
            }

            if (!PassWordHelper.VerifyHashedPassword(clientUser.PasswordHash, model.Password))
            {
                return(ResponseResult(ResultType.Failure, ResultCode.FailureSignIn, "登录失败,用户密码错误"));
            }

            LoginResultModel resultModel = new LoginResultModel(clientUser, model.DeviceId);

            return(ResponseResult(ResultType.Success, ResultCode.Success, "登录成功", resultModel));
        }
        public CustomJsonResult Add(AddViewModel model)
        {
            SysSalesmanUser user = new SysSalesmanUser();

            var agent = CurrentDb.SysAgentUser.Where(m => m.Id == this.CurrentUserId).FirstOrDefault();

            user.UserName     = string.Format("{0}{1}", agent.UserName, model.SysSalesmanUser.UserName);
            user.AgentId      = agent.Id;
            user.FullName     = model.SysSalesmanUser.FullName;
            user.PasswordHash = PassWordHelper.HashPassword("888888");
            user.Email        = model.SysSalesmanUser.Email;
            user.PhoneNumber  = model.SysSalesmanUser.PhoneNumber;
            user.IsDelete     = false;
            user.Status       = Enumeration.UserStatus.Normal;
            user.Type         = Enumeration.UserType.Salesman;

            return(SysFactory.AuthorizeRelay.CreateUser <SysSalesmanUser>(this.CurrentUserId, user));
        }
Beispiel #18
0
        public APIResponse AddChildAccount(AddChildAccountModel model)
        {
            var token = CurrentDb.SysSmsSendHistory.Where(m => m.Token == model.Token && m.ValidCode == model.ValidCode && m.IsUse == false && m.ExpireTime >= DateTime.Now).FirstOrDefault();

            if (token == null)
            {
                return(ResponseResult(ResultType.Failure, ResultCode.Failure, "验证码错误"));
            }


            var isExists = CurrentDb.SysClientUser.Where(m => m.UserName == model.AccountPhone).FirstOrDefault();

            if (isExists != null)
            {
                return(ResponseResult(ResultType.Failure, ResultCode.Failure, "该手机号码已经存在"));
            }

            token.IsUse = true;

            SysClientUser sysClientUser = new SysClientUser();

            sysClientUser.UserName             = model.AccountPhone;
            sysClientUser.FullName             = model.AccountFullName;
            sysClientUser.PhoneNumber          = model.AccountPhone;
            sysClientUser.PasswordHash         = PassWordHelper.HashPassword(model.AccountPassword);
            sysClientUser.SecurityStamp        = Guid.NewGuid().ToString();
            sysClientUser.PhoneNumberConfirmed = true;
            sysClientUser.MerchantId           = model.MerchantId;
            sysClientUser.RegisterTime         = DateTime.Now;
            sysClientUser.ClientAccountType    = Enumeration.ClientAccountType.SubAccount;
            sysClientUser.Status     = Enumeration.UserStatus.Normal;
            sysClientUser.CreateTime = DateTime.Now;
            sysClientUser.Creator    = model.UserId;
            CurrentDb.SysClientUser.Add(sysClientUser);
            CurrentDb.SaveChanges();


            APIResult result = new APIResult()
            {
                Result = ResultType.Success, Code = ResultCode.Success, Message = "添加成功"
            };

            return(new APIResponse(result));
        }
        public WebAPIReponse SignIn([FromBody] UserAccountRequest userAccount)
        {
            try
            {
                AccountInfo mtsAccountInfo = new AccountInfo();
                mtsAccountInfo.UserID = userAccount.LoginAccount;
                PassWordHelper passWordHelper = new PassWordHelper(userAccount.LoginPassword);
                mtsAccountInfo.PassWord = passWordHelper.CrtPassWord();
                var userInfo = _usersService.Login(mtsAccountInfo);
                if (userInfo != null)
                {
                    // 校验密码,生成 Token
                    JwtAuthUtil   jwtAuthUtil = new JwtAuthUtil();
                    JwtAuthObject jwtAuthInfo = new JwtAuthObject
                    {
                        UserName = userInfo.UserID,
                    };
                    switch (userAccount.LoginPlatform)
                    {
                    case SoftPlatform.mtsToolCaliburn:
                        jwtAuthInfo.ExpiryDateTime = DateTime.Now.AddHours(12).ToString(); break;

                    case SoftPlatform.mtsToolLoggerCenter:
                        jwtAuthInfo.ExpiryDateTime = DateTime.Now.AddHours(4).ToString(); break;

                    case SoftPlatform.mtsToolsSchedule:
                        jwtAuthInfo.ExpiryDateTime = DateTime.Now.AddMinutes(15).ToString(); break;

                    case SoftPlatform.mtsToolsStudio:
                        jwtAuthInfo.ExpiryDateTime = DateTime.Now.AddHours(4).ToString(); break;

                    default: jwtAuthInfo.ExpiryDateTime = DateTime.Now.AddMinutes(5).ToString(); break;
                    }
                    string jwtToken = jwtAuthUtil.GenerateToken(jwtAuthInfo);
                    return(new WebAPIReponse(HttpStatusCode.OK, "OK", jwtToken));
                }
                return(new WebAPIReponse(HttpStatusCode.NonAuthoritativeInformation, "Access Denied"));
            }
            catch (Exception exception)
            {
                return(new WebAPIReponse(HttpStatusCode.PreconditionFailed, "Precondition Failed", exception.ToString()));
            }
        }
        public CustomJsonResult AddChildAccount(int operater, int userId, string fullName, string phoneNumber)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {
                var masterAccount = CurrentDb.SysClientUser.Where(m => m.Id == userId).FirstOrDefault();
                var subAccount    = new SysClientUser();
                subAccount.UserName          = Guid.NewGuid().ToString().Replace("-", "");
                subAccount.PasswordHash      = PassWordHelper.HashPassword("888888");
                subAccount.SecurityStamp     = Guid.NewGuid().ToString();
                subAccount.RegisterTime      = this.DateTime;
                subAccount.CreateTime        = this.DateTime;
                subAccount.Creator           = operater;
                subAccount.ClientAccountType = Enumeration.ClientAccountType.SubAccount;
                subAccount.MerchantId        = masterAccount.MerchantId;
                subAccount.FullName          = fullName;
                subAccount.PhoneNumber       = phoneNumber;
                subAccount.Status            = Enumeration.UserStatus.Normal;

                CurrentDb.SysClientUser.Add(subAccount);
                CurrentDb.SaveChanges();

                var clientCode = CurrentDb.SysClientCode.Where(m => m.Id == subAccount.Id).FirstOrDefault();
                if (clientCode == null)
                {
                    return(new CustomJsonResult(ResultType.Failure, "开户失败,原因获取不到商户代码 "));
                }

                subAccount.ClientCode = clientCode.Code;
                subAccount.UserName   = clientCode.Code;


                CurrentDb.SaveChanges();
                ts.Complete();

                result      = new CustomJsonResult(ResultType.Success, "开户成功");
                result.Data = subAccount;
            }

            return(result);
        }
Beispiel #21
0
        public JsonResult Login(string account, string password)
        {
            string md5_salt_password = PassWordHelper.Md532Salt(password, account);
            AdminLoginViewModel adminLoginViewModel = null;

            if (IsAdminExists(account, md5_salt_password))
            {
                var admin = _context.Admin.First(a => a.LoginAccount == account && a.PassWord == md5_salt_password);


                SaveSession("username", admin.AdminName);
                SaveSession("admin_id", admin.Id.ToString());
                SaveSession("permission", admin.Permissions.ToString());
                SaveSession("account", admin.LoginAccount);
                SaveSession("token", PassWordHelper.Md532Salt(GetSession("admin_id") + GetSession("username") + GetSession("permission"), GetSession("account")));
                //string admin_id = GetSession("admin_id");
                //string username = GetSession("username");
                //string permission = GetSession("permission");
                //string account = GetSession("account");
                //string token = GetSession("token");



                adminLoginViewModel = new AdminLoginViewModel()
                {
                    UserName   = admin.AdminName,
                    UserId     = admin.Id,
                    status     = 200,
                    Permission = admin.Permissions,
                    Account    = admin.LoginAccount,
                    Token      = PassWordHelper.Md532Salt(admin.Id + admin.AdminName + admin.Permissions, account)
                };
                return(Json(adminLoginViewModel));
            }
            adminLoginViewModel = new AdminLoginViewModel()
            {
                status = 400
            };

            return(Json(adminLoginViewModel));
        }
Beispiel #22
0
        public JsonResult ResetPwd(int?id)
        {
            ResetPwdModel resetPwdModel = null;

            if (!IsSafe())
            {
                resetPwdModel = new ResetPwdModel()
                {
                    Code    = 519,
                    Message = "管理员账号状态存在异常,请联系运维人员"
                };
                return(Json(resetPwdModel));
            }

            var admin = _context.Admin.FirstOrDefault(a => a.Id == id);

            if (admin == null)
            {
                resetPwdModel = new ResetPwdModel()
                {
                    Code    = 518,
                    Message = "该用户状态异常,请联系运维人员"
                };
                return(Json(resetPwdModel));
            }

            string password     = PassWordHelper.GenerateCheckCode(8);
            string database_pwd = PassWordHelper.Md532Salt(password, admin.LoginAccount);

            admin.PassWord = database_pwd;
            _context.Update(admin);
            _context.SaveChanges();

            resetPwdModel = new ResetPwdModel()
            {
                Code    = 520,
                Message = $"密码重置成功,该管理员密码为{password},请妥善保管",
                NewPwd  = database_pwd
            };
            return(Json(resetPwdModel));
        }
        public APIResponse ChangePassword(ChangePasswordModel model)
        {
            var clientUser = CurrentDb.SysClientUser.Where(m => m.Id == model.UserId).FirstOrDefault();

            if (clientUser == null)
            {
                return(ResponseResult(ResultType.Failure, ResultCode.FailureUserNameNotExists, "用户名不存在"));
            }

            if (!PassWordHelper.VerifyHashedPassword(clientUser.PasswordHash, model.OldPassword))
            {
                return(ResponseResult(ResultType.Failure, ResultCode.Failure, "修改失败,旧密码错误"));
            }

            clientUser.PasswordHash   = PassWordHelper.HashPassword(model.NewPassword);
            clientUser.Mender         = model.UserId;
            clientUser.LastUpdateTime = DateTime.Now;
            CurrentDb.SaveChanges();

            return(ResponseResult(ResultType.Success, ResultCode.Success, "修改成功"));
        }
Beispiel #24
0
        public async Task <bool> Create(string account, string password, string name, int permission)
        {
            Admin admin = new Admin()
            {
                LoginAccount = account,
                PassWord     = PassWordHelper.Md532Salt(password, account),
                AdminName    = name,
                Permissions  = permission,
                CreateTime   = DateTime.Now
            };

            if (ModelState.IsValid)
            {
                _context.Add(admin);
                await _context.SaveChangesAsync();

                return(true);
            }

            return(false);
        }
        public CustomJsonResult ChangePassword(int operater, int userId, string oldpassword, string newpassword)
        {
            var sysUser = _db.SysUser.Where(m => m.Id == userId).FirstOrDefault();

            if (sysUser != null)
            {
                if (!PassWordHelper.VerifyHashedPassword(sysUser.PasswordHash, oldpassword))
                {
                    return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "旧密码不正确"));
                }

                sysUser.PasswordHash   = PassWordHelper.HashPassword(newpassword);
                sysUser.Mender         = operater;
                sysUser.LastUpdateTime = DateTime.Now;

                _db.SaveChanges();
            }


            return(new CustomJsonResult(ResultType.Success, ResultCode.Success, "修改成功"));
        }
Beispiel #26
0
        public CustomJsonResult Login(RopMachineLogin rop)
        {
            var machine = CurrentDb.Machine.Where(m => m.Id == rop.MachineId).FirstOrDefault();

            if (machine == null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "登录失败,该机器未登记"));
            }

            var sysMerchantUser = CurrentDb.SysMerchUser.Where(m => m.UserName == rop.UserName).FirstOrDefault();

            if (sysMerchantUser == null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "登录失败,用户名或密码错误"));
            }

            var isPasswordCorrect = PassWordHelper.VerifyHashedPassword(sysMerchantUser.PasswordHash, rop.Password);

            if (!isPasswordCorrect)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "登录失败,用户名或密码错误"));
            }

            if (sysMerchantUser.MerchId != machine.MerchId)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "帐号与商户不对应"));
            }

            var ret = new RetMachineLogin();

            ret.UserId   = sysMerchantUser.Id;
            ret.UserName = sysMerchantUser.UserName;
            ret.FullName = sysMerchantUser.FullName;

            return(new CustomJsonResult(ResultType.Success, ResultCode.Success, "登录成功", ret));
        }
Beispiel #27
0
        public CustomJsonResult LoginByMinProgram(RopOwnLoginByMinProgram rop)
        {
            var result = new CustomJsonResult();
            var ret    = new RetOwnLoginByMinProgram();

            var merch = CurrentDb.Merch.Where(m => m.Id == rop.MerchId && m.WxMpAppId == rop.AppId).FirstOrDefault();

            if (merch == null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "商户信息认证失败"));
            }

            var wxAppInfoConfig = new WxAppInfoConfig();

            wxAppInfoConfig.AppId               = merch.WxMpAppId;
            wxAppInfoConfig.AppSecret           = merch.WxMpAppSecret;
            wxAppInfoConfig.PayMchId            = merch.WxPayMchId;
            wxAppInfoConfig.PayKey              = merch.WxPayKey;
            wxAppInfoConfig.PayResultNotifyUrl  = merch.WxPayResultNotifyUrl;
            wxAppInfoConfig.NotifyEventUrlToken = merch.WxPaNotifyEventUrlToken;


            var wxUserInfoByMinProram = SdkFactory.Wx.GetUserInfoByMinProramJsCode(wxAppInfoConfig, rop.EncryptedData, rop.Iv, rop.Code);

            if (wxUserInfoByMinProram == null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "获取微信用户信息失败"));
            }

            var wxUserInfo = CurrentDb.WxUserInfo.Where(m => m.OpenId == wxUserInfoByMinProram.openId).FirstOrDefault();

            if (wxUserInfo == null)
            {
                string sysClientUserId = GuidUtil.New();

                var sysClientUser = new SysClientUser();

                sysClientUser.Id            = sysClientUserId;
                sysClientUser.UserName      = string.Format("wx{0}", Guid.NewGuid().ToString().Replace("-", ""));
                sysClientUser.PasswordHash  = PassWordHelper.HashPassword("888888");
                sysClientUser.SecurityStamp = Guid.NewGuid().ToString();
                sysClientUser.RegisterTime  = DateTime.Now;
                sysClientUser.Nickname      = wxUserInfoByMinProram.nickName;
                sysClientUser.Sex           = wxUserInfoByMinProram.gender;
                sysClientUser.Province      = wxUserInfoByMinProram.province;
                sysClientUser.City          = wxUserInfoByMinProram.city;
                sysClientUser.Country       = wxUserInfoByMinProram.country;
                sysClientUser.Avatar        = wxUserInfoByMinProram.avatarUrl;
                sysClientUser.IsVip         = false;
                sysClientUser.CreateTime    = DateTime.Now;
                sysClientUser.Creator       = sysClientUserId;
                sysClientUser.BelongSite    = Enumeration.BelongSite.Client;
                CurrentDb.SysClientUser.Add(sysClientUser);
                CurrentDb.SaveChanges();

                wxUserInfo              = new WxUserInfo();
                wxUserInfo.Id           = GuidUtil.New();
                wxUserInfo.MerchId      = rop.MerchId;
                wxUserInfo.AppId        = rop.AppId;
                wxUserInfo.ClientUserId = sysClientUser.Id;
                wxUserInfo.OpenId       = wxUserInfoByMinProram.openId;
                wxUserInfo.CreateTime   = DateTime.Now;
                wxUserInfo.Creator      = sysClientUserId;
                CurrentDb.WxUserInfo.Add(wxUserInfo);
                CurrentDb.SaveChanges();
            }
            else
            {
                var sysClientUser = CurrentDb.SysClientUser.Where(m => m.Id == wxUserInfo.ClientUserId).FirstOrDefault();
                if (sysClientUser != null)
                {
                    sysClientUser.Nickname = wxUserInfoByMinProram.nickName;
                    sysClientUser.Sex      = wxUserInfoByMinProram.gender;
                    sysClientUser.Province = wxUserInfoByMinProram.province;
                    sysClientUser.City     = wxUserInfoByMinProram.city;
                    sysClientUser.Country  = wxUserInfoByMinProram.country;
                    sysClientUser.Avatar   = wxUserInfoByMinProram.avatarUrl;
                }
                CurrentDb.SaveChanges();
            }

            var tokenInfo = new TokenInfo();

            ret.Token        = GuidUtil.New();
            tokenInfo.UserId = wxUserInfo.ClientUserId;

            SSOUtil.SetTokenInfo(ret.Token, tokenInfo, new TimeSpan(1, 0, 0));

            result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "登录成功", ret);

            return(result);
        }
        private APIResponse ClientLogin(LoginModel model)
        {
            string testAccount  = "15989287032";
            string testDeviceId = "000000000000000";

            var clientUser = CurrentDb.SysClientUser.Where(m => m.UserName == model.UserName).FirstOrDefault();

            if (clientUser == null)
            {
                return(ResponseResult(ResultType.Failure, ResultCode.FailureSignIn, "登录失败,用户名不存在"));
            }


            if (!PassWordHelper.VerifyHashedPassword(clientUser.PasswordHash, model.Password))
            {
                return(ResponseResult(ResultType.Failure, ResultCode.FailureSignIn, "登录失败,用户密码错误"));
            }


            var posMachine = CurrentDb.PosMachine.Where(m => m.DeviceId == model.DeviceId).FirstOrDefault();

            if (model.UserName != testAccount)
            {
                if (posMachine == null)
                {
                    return(ResponseResult(ResultType.Failure, ResultCode.FailureSignIn, "登录失败,设备没有注册"));
                }
            }
            else
            {
                posMachine = CurrentDb.PosMachine.Where(m => m.DeviceId == testDeviceId).FirstOrDefault();
            }

            var merchantPosMachine = CurrentDb.MerchantPosMachine.Where(m => m.UserId == clientUser.Id && m.MerchantId == clientUser.MerchantId).FirstOrDefault();

            if (merchantPosMachine == null)
            {
                return(ResponseResult(ResultType.Failure, ResultCode.FailureSignIn, "登录失败,设备与用户不匹配"));
            }

            if (merchantPosMachine.PosMachineId != posMachine.Id)
            {
                //内测账号,不验证设备ID
                if (model.UserName != testAccount)
                {
                    return(ResponseResult(ResultType.Failure, ResultCode.FailureSignIn, "登录失败,设备与用户不匹配"));
                }
            }

            if (merchantPosMachine.Status == Enumeration.MerchantPosMachineStatus.Unknow)
            {
                return(ResponseResult(ResultType.Failure, ResultCode.FailureSignIn, "登录失败,用户状态异常"));
            }

            LoginResultModel resultModel = new LoginResultModel();

            if (merchantPosMachine.Status == Enumeration.MerchantPosMachineStatus.Normal)
            {
                resultModel.Status = ClientLoginStatus.Normal;
            }
            else if (merchantPosMachine.Status == Enumeration.MerchantPosMachineStatus.NoActive)
            {
                resultModel.Status = ClientLoginStatus.NoActive;
            }
            else if (merchantPosMachine.Status == Enumeration.MerchantPosMachineStatus.Expiry)
            {
                resultModel.Status = ClientLoginStatus.Expiry;
            }
            else if (merchantPosMachine.ExpiryTime < DateTime.Now)
            {
                resultModel.Status        = ClientLoginStatus.Expiry;
                merchantPosMachine.Status = Enumeration.MerchantPosMachineStatus.Expiry;
                CurrentDb.SaveChanges();
            }

            resultModel.UserId        = clientUser.Id;
            resultModel.UserName      = clientUser.UserName;
            resultModel.MerchantId    = clientUser.MerchantId;
            resultModel.MerchantCode  = clientUser.ClientCode;
            resultModel.IsTestAccount = clientUser.IsTestAccount;
            resultModel.PosMachineId  = posMachine.Id;

            var orderToServiceFee = CurrentDb.OrderToServiceFee.Where(m => m.UserId == clientUser.Id && m.Status == Enumeration.OrderStatus.WaitPay).FirstOrDefault();

            if (orderToServiceFee != null)
            {
                resultModel.OrderInfo = BizFactory.Merchant.GetOrderConfirmInfoByServiceFee(orderToServiceFee);
            }

            return(ResponseResult(ResultType.Success, ResultCode.Success, "登录成功", resultModel));
        }
Beispiel #29
0
        public CustomJsonResult Add(string operater, string merchId, RopUserAdd rop)
        {
            var result = new CustomJsonResult();

            if (string.IsNullOrEmpty(rop.UserName))
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "用户名不能为空"));
            }

            if (string.IsNullOrEmpty(rop.Password))
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "密码不能为空"));
            }

            var isExistUserName = CurrentDb.SysUser.Where(m => m.UserName == rop.UserName).FirstOrDefault();

            if (isExistUserName != null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, string.Format("该用户名({0})已被使用", rop.UserName)));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                var merchUser = new SysMerchUser();
                merchUser.Id            = GuidUtil.New();
                merchUser.UserName      = rop.UserName;
                merchUser.FullName      = rop.FullName;
                merchUser.PasswordHash  = PassWordHelper.HashPassword(rop.Password);
                merchUser.Email         = rop.Email;
                merchUser.PhoneNumber   = rop.PhoneNumber;
                merchUser.BelongSite    = Enumeration.BelongSite.Agent;
                merchUser.IsDelete      = false;
                merchUser.IsDisable     = false;
                merchUser.IsMaster      = false;
                merchUser.MerchId       = merchId;
                merchUser.Creator       = operater;
                merchUser.CreateTime    = DateTime.Now;
                merchUser.RegisterTime  = DateTime.Now;
                merchUser.SecurityStamp = Guid.NewGuid().ToString().Replace("-", "");
                CurrentDb.SysMerchUser.Add(merchUser);

                if (rop.RoleIds != null)
                {
                    foreach (var roleId in rop.RoleIds)
                    {
                        if (!string.IsNullOrEmpty(roleId))
                        {
                            CurrentDb.SysUserRole.Add(new SysUserRole {
                                Id = GuidUtil.New(), RoleId = roleId, UserId = merchUser.Id, Creator = operater, CreateTime = DateTime.Now
                            });
                        }
                    }
                }

                CurrentDb.SaveChanges();
                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "保存成功");
            }

            return(result);
        }
Beispiel #30
0
        public CustomJsonResult Add(string operater, RopMerchMasterAdd rop)
        {
            var result = new CustomJsonResult();

            if (string.IsNullOrEmpty(rop.UserName))
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "用户名不能为空"));
            }

            if (string.IsNullOrEmpty(rop.Password))
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "密码不能为空"));
            }

            var isExistUserName = CurrentDb.SysUser.Where(m => m.UserName == rop.UserName).FirstOrDefault();

            if (isExistUserName != null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, string.Format("该用户名({0})已被使用", rop.UserName)));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                string merchId = GuidUtil.New();

                var user = new SysMerchUser();
                user.Id            = GuidUtil.New();
                user.MerchId       = merchId;
                user.PId           = GuidUtil.Empty();
                user.UserName      = rop.UserName;
                user.FullName      = rop.FullName;
                user.PasswordHash  = PassWordHelper.HashPassword(rop.Password);
                user.Email         = rop.Email;
                user.PhoneNumber   = rop.PhoneNumber;
                user.BelongSite    = Enumeration.BelongSite.Merch;
                user.IsDelete      = false;
                user.IsDisable     = false;
                user.IsMaster      = true;
                user.Creator       = operater;
                user.CreateTime    = DateTime.Now;
                user.RegisterTime  = DateTime.Now;
                user.SecurityStamp = Guid.NewGuid().ToString().Replace("-", "");
                CurrentDb.SysMerchUser.Add(user);

                var merch = new LocalS.Entity.Merch();
                merch.Id         = merchId;
                merch.UserId     = user.Id;
                merch.Name       = rop.FullName;
                merch.CreateTime = DateTime.Now;
                merch.Creator    = operater;
                CurrentDb.Merch.Add(merch);

                var sysRole = CurrentDb.SysRole.Where(m => m.BelongSite == Enumeration.BelongSite.Merch && m.IsSuper == true).FirstOrDefault();
                if (sysRole == null)
                {
                    return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "未配置系统管理角色"));
                }


                CurrentDb.SysUserRole.Add(new SysUserRole {
                    Id = GuidUtil.New(), RoleId = sysRole.Id, UserId = user.Id, Creator = operater, CreateTime = DateTime.Now
                });


                var sysOrg = new SysOrg();
                sysOrg.Id          = GuidUtil.New();
                sysOrg.Name        = "根组织";
                sysOrg.PId         = GuidUtil.Empty();
                sysOrg.BelongSite  = Enumeration.BelongSite.Merch;
                sysOrg.ReferenceId = merch.Id;
                sysOrg.IsDelete    = false;
                sysOrg.Priority    = 0;
                sysOrg.Depth       = 0;
                sysOrg.CreateTime  = DateTime.Now;
                sysOrg.Creator     = operater;
                CurrentDb.SysOrg.Add(sysOrg);

                var sysUserOrg = new SysUserOrg();
                sysUserOrg.Id         = GuidUtil.New();
                sysUserOrg.OrgId      = sysOrg.Id;
                sysUserOrg.UserId     = user.Id;
                sysUserOrg.CreateTime = DateTime.Now;
                sysUserOrg.Creator    = operater;
                CurrentDb.SysUserOrg.Add(sysUserOrg);

                CurrentDb.SaveChanges();
                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "新建成功");
            }

            return(result);
        }