Exemplo n.º 1
0
        public IHttpActionResult GetUserByLoginName(string loginName)
        {
            UserEntity   userEntity = new UserEntity();
            ResultEntity result     = new ResultEntity();

            try
            {
                USER temp = dal.FindUserByLoginName(loginName);
                userEntity = temp.ToUserEntity();
                //不返回密码信息
                userEntity.Password = "";
                if (temp.COMPANY != null)
                {
                    userEntity.Company = temp.COMPANY.ToCompanyEntity();
                }
                userEntity.Accounts = temp.ACCOUNTs.ToList <ACCOUNT>().ConvertAll <AccountEntity>(a => a.ToAccountEntity());
                userEntity.Roles    = temp.ROLEs.ToList <ROLE>().ConvertAll <RoleEntity>(r => r.ToRoleEntity());
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                NtripProxyLogger.LogExceptionIntoFile("调用接口api/User/GetUserByLoginName/{loginName}异常,异常信息为:" + e.Message);
            }

            result.IsSuccess = result.Message == null;
            result.Data      = userEntity;
            return(Json <ResultEntity>(result));
        }
Exemplo n.º 2
0
        public IHttpActionResult Login(UserEntity user)
        {
            //是否允许登陆
            bool         allowLogin = false;
            ResultEntity result     = new ResultEntity();

            try
            {
                allowLogin = dal.LoginCheck(user.ToUSER());
                if (allowLogin)
                {
                    USER       temp = dal.FindUserByLoginName(user.Login);
                    UserEntity data = new UserEntity();
                    data = temp.ToUserEntity();
                    //不返回密码信息
                    data.Password = "";
                    //转换添加的账号信息
                    data.Accounts = temp.ACCOUNTs.ToList <ACCOUNT>().ConvertAll <AccountEntity>(a => a.ToAccountEntity());
                    //转换公司信息
                    data.Company = temp.COMPANY.ToCompanyEntity();
                    //转换角色信息
                    data.Roles = temp.ROLEs.ToList <ROLE>().ConvertAll <RoleEntity>(r => r.ToRoleEntity());
                    foreach (var role in data.Roles)
                    {
                        //转换角色中的权限信息
                        role.Permissions = temp.ROLEs.FirstOrDefault <ROLE>(r => r.ID == role.ID)
                                           .PERMISSIONs.ToList <PERMISSION>().ConvertAll <PermissionEntity>(p => p.ToPermissionEntity());
                        foreach (var permission in role.Permissions)
                        {
                            //转换权限中的目录信息
                            permission.Menus = temp.ROLEs.FirstOrDefault <ROLE>(r => r.ID == role.ID)
                                               .PERMISSIONs.FirstOrDefault <PERMISSION>(p => p.ID == permission.ID)
                                               .MENUs.ToList <MENU>().ConvertAll <MenuEntity>(m => m.ToMenuEntity());
                        }
                    }
                    result.Data = data;
                    //获取访问的ip地址
                    string ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                    //NLog记录日志
                    LogEventInfo logInfo = new LogEventInfo(LogLevel.Info, "", "");
                    logInfo.Properties["Log_Time"]    = DateTime.Now;
                    logInfo.Properties["Log_User"]    = user.ID;
                    logInfo.Properties["Log_Action"]  = "用户登录";
                    logInfo.Properties["Log_Module"]  = "登录模块";
                    logInfo.Properties["Log_Message"] = "登录ip地址为" + ip;
                    NtripProxyLogger.LogActionIntoDatabase(logInfo);
                }
                else
                {
                    result.IsSuccess = false;
                    result.Data      = "用户名或密码错误";
                }
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                NtripProxyLogger.LogExceptionIntoFile("调用接口api/User/Login异常,异常信息为:" + e.Message);
            }

            result.IsSuccess = allowLogin;
            return(Json <ResultEntity>(result));
        }