public async System.Threading.Tasks.Task <string> Index(UserVerify data)
        {
            string un       = data.UserName;
            string Password = data.Password;
            string Baseurl  = "http://localhost:59713/";

            using (var client = new HttpClient())
            {
                //Passing service base url
                client.BaseAddress = new Uri(Baseurl);

                client.DefaultRequestHeaders.Clear();
                //Define request data format
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                //Sending request to find web api REST service resource GetAllEmployees using HttpClient

                var Res = await client.GetAsync("api/UserLogins/AuthenticateUser?id=0&UserID=" + un + "&Password="******"1");
                }
                else
                {
                    return("-1");
                }
            }
        }
Example #2
0
        public IActionResult VerifyEmail(VerifyEmailRequest model)
        {
            try
            {
                bool isCodeValid = _authService.VerifyCode(model.Token, model.UserId);

                if (isCodeValid)
                {
                    UserVerify userVerify = new UserVerify
                    {
                        Message = "Verification successful, you can now login"
                    };
                    return(Ok(userVerify));
                }
                else
                {
                    // return statusCode not allowed with a message
                    return(StatusCode(StatusCodes.Status403Forbidden, "Verification code is invalid"));
                }
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
Example #3
0
        public string GenerateNavigatorTreeJson(int block)
        {
            UserData            userInfo    = ((CustomPrincipal)HttpContext.User).UserData;
            UserVerify          uv          = new UserVerify(RMUrl);
            string              CultureFlag = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
            string              zTreeJsom   = string.Empty;
            List <TreeMenuItem> menuLst     = new List <TreeMenuItem>();
            List <TreeMenuItem> menuLst1    = new List <TreeMenuItem>();
            List <TreeMenuItem> allMenuItem = this.HttpContext.Application["Functions"] as List <TreeMenuItem>;

            if (userInfo.IsSuperAdmin)
            {
                menuLst = allMenuItem;
            }
            else
            {
                SingleSystemLoginModel userModel = uv.GetLoginModel(userInfo.LoginName, userInfo.Password);
                List <string>          nodes     = new List <string>();
                foreach (string str in userModel.SubFunctionIDs)
                {
                    nodes.AddRange(GetNode(str, allMenuItem));
                }
                menuLst = allMenuItem.Where(i => nodes.Distinct().Contains(i.GUID)).ToList();
            }
            Session["Nodes"] = menuLst.Select(i => i.SubfunctionCode)
                               .Where(i => !string.IsNullOrEmpty(i)).ToList();
            menuLst.ForEach(i => i.ModuleID = i.ModuleID ?? string.Empty);
            menuLst1  = menuLst.FindAll(i => i.Level != 3);
            zTreeJsom = GenerateJson(CultureFlag, menuLst1, block);
            return(zTreeJsom);
        }
Example #4
0
 public ActionResult GetRolePermission(string id)
 {
     ViewData["RoleGuid"] = id;
     ViewData["RoleName"] = new UserVerify(this.RMUrl).GetRoles()
                            .Find(i => i.LocalRoleSymbolID.Equals(id)).LocalRoleName;
     return(View("RolePermission"));
 }
Example #5
0
        public string UpdRole(Role r)
        {
            bool result = false;

            if (string.IsNullOrEmpty(r.Guid))
            {
                r.Guid = Guid.NewGuid().ToString();
                result = new UserVerify(this.RMUrl).AddRole(r.Name);
            }
            else
            {
                result = new UserVerify(this.RMUrl).UpdRole(r.Guid, r.Name);
            }

            //new RolePermission().UpdRole(r);
            string msg = string.Empty;

            if (result)
            {
                msg = General.Resource.Common.Success;
            }
            else
            {
                msg = General.Resource.Common.Failed;
            }
            return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}"
                                 , result.ToString().ToLower(), msg));
        }
Example #6
0
        public string GetPermission(string id)
        {
            //List<string> selectedItems = new RolePermission().GetRolePermission(id);
            List <string> selectedItems = new UserVerify(RMUrl).GetRolePermission(id)
                                          .Select(i => i.SubfunctionID).Distinct().ToList();
            string              CultureFlag  = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
            StringBuilder       strJson      = new StringBuilder("[ ");
            List <string>       saasModules  = this.HttpContext.Application["SaasModules"] as List <string>;
            List <TreeMenuItem> allMenuNodes = this.HttpContext.Application["Functions"] as List <TreeMenuItem>;
            List <TreeMenuItem> menuLst      = allMenuNodes.Where(i => saasModules.Contains(i.GUID) || saasModules.Contains(i.ModuleID))
                                               .Distinct().ToList();

            menuLst.ForEach(i => i.ModuleID = i.ModuleID ?? string.Empty);
            return(GenerateJson(CultureFlag, menuLst, selectedItems));
        }
Example #7
0
        public string GetRoles()
        {
            StringBuilder strJson      = new StringBuilder("[ ");
            string        strFormatter = "{{\"Name\":\"{0}\",\"Guid\":\"{1}\"}},";
            //List<Role> roles = new RolePermission().GetRoles(base.SystemName);
            List <T_LocalRole> roles = new UserVerify(this.RMUrl).GetRoles();

            foreach (T_LocalRole r in roles)
            {
                strJson.AppendFormat(strFormatter, r.LocalRoleName, r.LocalRoleSymbolID);
            }
            strJson.Remove(strJson.Length - 1, 1);
            strJson.Append("]");
            return(strJson.ToString());
        }
Example #8
0
        public Task <UserVerify> GetEditApproval(string UserID)
        {
            UserVerify UserExist = new UserVerify();

            try
            {
                string    conn = _appConfiguration.GetConnectionString(PlexformConsts.ESWISConnectionString);
                UsrVerify obj  = new UsrVerify(conn);
                UserExist = obj.GetApprovalEdit(UserID);
            }
            catch (Exception ex)
            {
                var temp = ex.ToString();
            }
            return(Task.FromResult(UserExist));
        }
Example #9
0
        public string DelRole(string id)
        {
            //bool result = new RolePermission().DelRole(id);
            bool   result = new UserVerify(RMUrl).DelRole(id);
            string msg    = string.Empty;

            if (result)
            {
                msg = General.Resource.Common.Success;
            }
            else
            {
                msg = General.Resource.Common.Failed;
            }
            return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}"
                                 , result.ToString().ToLower(), msg));
        }
Example #10
0
        public string UpdRolePermission(string RoleID, string Funs)
        {
            //R_LocalRole_Subfunction
            List <string> funs = Funs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            //bool result = new RolePermission().UpdRolePermission(RoleID, funs);
            List <R_LocalRole_Subfunction> rfs     = new List <R_LocalRole_Subfunction>();
            R_LocalRole_Subfunction        item    = new R_LocalRole_Subfunction();
            List <TreeMenuItem>            menuLst = this.HttpContext.Application["Functions"] as List <TreeMenuItem>;
            TreeMenuItem menuItem = new TreeMenuItem();
            string       msg      = string.Empty;

            foreach (string fun in funs)
            {
                menuItem = menuLst.Find(i => i.GUID.Equals(fun));
                item     = new R_LocalRole_Subfunction()
                {
                    CreateDate             = DateTime.Now,
                    CreateUTCDate          = DateTime.UtcNow,
                    LocalRoleSymbolID      = RoleID,
                    ModuleID               = string.IsNullOrEmpty(menuItem.ModuleID) ? fun : menuItem.ModuleID,
                    SubfunctionEnglishName = menuItem.EnglishName,
                    SubfunctionID          = fun,
                    SubfunctionName        = menuItem.ChineseName,
                    SystemID               = SubSystemID,
                    SystemName             = SystemName
                };
                rfs.Add(item);
            }
            bool result = new UserVerify(RMUrl).UpdRolePermission(RoleID, rfs);

            if (result)
            {
                msg = General.Resource.Common.Success;
            }
            else
            {
                msg = General.Resource.Common.Failed;
            }
            return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}"
                                 , result.ToString().ToLower(), msg));
        }
Example #11
0
 public ActionResult GetRole(string id = null)
 {
     if (string.IsNullOrEmpty(id))
     {
         return(View("Role", new Role()
         {
             SysName = base.SystemName
         }));
     }
     else
     {
         T_LocalRole role = new UserVerify(this.RMUrl).GetRoles()
                            .Find(i => i.LocalRoleSymbolID.Equals(id));
         Role r = new Role()
         {
             Guid    = role.LocalRoleSymbolID,
             Name    = role.LocalRoleName,
             SysName = role.SystemName,
         };
         return(View("Role", r));
     }
 }
Example #12
0
        public async Task <IActionResult> Login(User user)
        {
            ViewBag.UserName = user.UserName;

            var userver = UserVerify.LoginVerify(user);

            if (!userver.Item2)
            {
                ViewBag.Errormessage = userver.Item1;
                return(View());
            }

            user.PassWord = Encryption.MD5Str(user.PassWord);
            User model = await _userService.UserLogin(user);

            if (model == null)
            {
                ViewBag.Errormessage = "登录失败";
                return(View());
            }

            if (model.IsFreeze == true)
            {
                ViewBag.Errormessage = "该账号已冻结,禁止登录!";
                return(View());
            }

            //用户标识
            var identity = new ClaimsPrincipal(
                new ClaimsIdentity(new[] {
                new Claim(ClaimTypes.Sid, model.Code),
                new Claim(ClaimTypes.Name, model.UserName),
                new Claim(ClaimTypes.Thumbprint, model.HeadImg),
                new Claim(ClaimTypes.Role, model.Role.CName),
                new Claim(ClaimTypes.Email, model.Email),
                new Claim(ClaimTypes.HomePhone, model.Phone)
            }, CookieAuthenticationDefaults.AuthenticationScheme)
                );

            await HttpContext.SignInAsync(
                CookieAuthenticationDefaults.AuthenticationScheme,
                new ClaimsPrincipal(identity),
                new AuthenticationProperties
            {
                IsPersistent = true,
                ExpiresUtc   = DateTime.Now.AddMinutes(60)
            }
                );

            // 把user信息存储缓存
            _cacheService.Add(model.Code + "-" + SysConsts.USERINFO, model);

            model.LastLoginTime = DateTime.Now;
            await _userService.Update(model);

            string returnUrl = TempData["returnUrl"]?.ToString();

            if (string.IsNullOrEmpty(returnUrl))
            {
                return(RedirectToAction("Index", "Home"));
            }

            return(Redirect(returnUrl));
        }
Example #13
0
        /// <summary>
        /// 易班授权验证
        /// </summary>
        private void YbOauth()
        {
            try
            {
                #region 判断Code是否为空

                if (string.IsNullOrEmpty(Request.QueryString["code"]))
                {
                    LogDBHandleClass.getInstance().LogException(CValue.LOG_LEVEL_ERROR, "易班账号登录失败:code为NULL!");
                    UtilityHandler.WindowLocation("/Yb.html?yb=yb_loginerror");
                    return;
                }

                #endregion 判断Code是否为空

                #region 认证信息

                YbSDK.Api.OauthApi oauthApi = new YbSDK.Api.OauthApi();

                #endregion 认证信息

                #region 通过code获得AccessToken

                //通过code获得AccessToken
                string strUrl_AccessToken    = "https://openapi.yiban.cn/oauth/access_token";
                string strParam_AccessToken  = "client_id=" + oauthApi.context.Config.AppId + "&client_secret=" + oauthApi.context.Config.AppSecret + "&code=" + Request.QueryString["code"].ToString() + "&redirect_uri=" + oauthApi.context.Config.Callback;
                string strResult_AccessToken = HttpMethods.HttpPost(strUrl_AccessToken, strParam_AccessToken);
                //LogDBHandleClass.getInstance().LogException(CValue.LOG_LEVEL_INFO, "获取已授权用户的access_token:" + strResult_AccessToken);
                AccessToken accessToken = jss.Deserialize <AccessToken>(strResult_AccessToken);
                if (string.IsNullOrEmpty(accessToken.access_token))
                {
                    LogDBHandleClass.getInstance().LogException(CValue.LOG_LEVEL_ERROR, "易班账号登录失败:通过code获得AccessToken为NULL!");
                    UtilityHandler.WindowLocation("/Yb.html?yb=yb_loginerror");
                    return;
                }

                #endregion 通过code获得AccessToken

                #region 通过AccessToken获得用户信息

                //通过AccessToken获得用户信息
                string     strUrl_VerifyMe    = "https://openapi.yiban.cn/user/verify_me?access_token=" + accessToken.access_token;
                string     strResult_VerifyMe = HttpMethods.HttpGet(strUrl_VerifyMe);
                UserVerify userVerify         = jss.Deserialize <UserVerify>(strResult_VerifyMe);
                if (userVerify == null)
                {
                    RevokeToken(oauthApi, accessToken.access_token, "", "");
                    LogDBHandleClass.getInstance().LogException(CValue.LOG_LEVEL_ERROR, userVerify.info.yb_realname + " 易班账号登录失败:通过AccessToken获得用户信息为NULL!");
                    UtilityHandler.WindowLocation("/Yb.html?yb=yb_loginerror");
                    return;
                }

                #endregion 通过AccessToken获得用户信息

                #region 验证易班用户是否在资助系统中已经有注册用户

                //验证易班用户是否在资助系统中已经有注册用户
                string strUserId = userVerify.info.yb_studentid;//学号
                if (string.IsNullOrEmpty(strUserId))
                {
                    strUserId = userVerify.info.yb_employid;      //工号
                }
                string strUserName = userVerify.info.yb_realname; //姓名

                SqlParameter[] p = new SqlParameter[2];
                p[0] = new SqlParameter("@id", strUserId);
                p[1] = new SqlParameter("@name", strUserName);
                if (strUserId.Length == 0 || strUserName.Length == 0)
                {
                    RevokeToken(oauthApi, accessToken.access_token, strUserId, strUserName);
                    LogDBHandleClass.getInstance().LogException(CValue.LOG_LEVEL_ERROR, " 易班账号登录失败:" + strUserId + "易班账号为空或者" + strUserName + "易班真实用户名为空!");
                    UtilityHandler.WindowLocation("/Yb.html?yb=yb_noexist");
                    return;
                }

                //ZZ 20180901 新增:对接教务系统 Start
                //学生在易班登录的时候,通过教务系统对接接口获得学生在教务系统中的基础信息
                string jw_msg = string.Empty;
                if (!JWHandleClass.getInstance().ByJwInsertOrUpdateStuInfo("200812601079", out jw_msg))
                {
                    //RevokeToken(oauthApi, accessToken.access_token, strUserId, strUserName);
                    //LogDBHandleClass.getInstance().LogException(CValue.LOG_LEVEL_ERROR, strUserName + " 易班账号登录失败:对接教务系统,出错:"+ jw_msg);
                    UtilityHandler.WindowLocation("/Yb.html?yb=yb_noexist");
                    return;
                }
                //ZZ 20180901 新增:对接教务系统 End

                LogDBHandleClass.getInstance().LogException(CValue.LOG_LEVEL_INFO, "易班登录,学号或者工号:" + strUserId + " 真实姓名:" + strUserName);
                DataTable dtUser = ds.ExecuteTxtDataTable("SELECT * FROM UA_USER WHERE USER_ID=@id AND USER_NAME=@name", p);
                if (dtUser == null || dtUser.Rows.Count == 0)
                {
                    RevokeToken(oauthApi, accessToken.access_token, strUserId, strUserName);
                    LogDBHandleClass.getInstance().LogException(CValue.LOG_LEVEL_ERROR, strUserName + " 易班账号登录失败:资助系统不存在此用户!");
                    UtilityHandler.WindowLocation("/Yb.html?yb=yb_noexist");
                    return;
                }

                //更新易班token值到用户表中
                if (!ComHandleClass.getInstance().UpdateUaUser_YbToken(dtUser.Rows[0]["USER_ID"].ToString(), accessToken.access_token))
                {
                    RevokeToken(oauthApi, accessToken.access_token, strUserId, strUserName);
                    UtilityHandler.WindowLocation("/Yb.html?yb=yb_loginerror");
                    return;
                }

                string username = dtUser.Rows[0]["USER_ID"].ToString();
                string password = dtUser.Rows[0]["LOGIN_PW"].ToString();
                if (UserHandler.CheckLogin(username, password, true))
                {
                    //LogDBHandleClass.getInstance().LogOperation(strUserId, "用户易班登录", CValue.LOG_ACTION_TYPE_0, CValue.LOG_RECORD_TYPE_1, string.Format("用户易班登录:用户{0},用户名{1}", strUserId, strUserName), strUserId, strUserName, Fetch.UserIp);

                    UtilityHandler.WindowLocation("/Index.aspx?sid=" + accessToken.access_token);
                    return;
                }

                #endregion 验证易班用户是否在资助系统中已经有注册用户
            }
            catch (Exception ex)
            {
                //string strMsg = "易班账号登录失败:" + ex.ToString();
                //LogDBHandleClass.getInstance().LogException(CValue.LOG_LEVEL_ERROR, strMsg);
                UtilityHandler.WindowLocation("/Yb.html?yb=yb_loginerror");
                return;
            }
        }