Example #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        userid   = Request["uid"];
        password = Request["PWD"];

        JsonItem rv = new JsonItem();

        string realAccount = null;

        try
        {
            if (BPMConnection.Authenticate(YZAuthHelper.BPMServerName, YZAuthHelper.BPMServerPort, userid, password, out realAccount))
            {
                YZAuthHelper.SetAuthCookie(realAccount);
                YZAuthHelper.ClearLogoutFlag();

                rv.Attributes["success"] = true;
                rv.Attributes["text"]    = "登陆成功";
            }
        }
        catch (Exception ex)
        {
            rv.Attributes["success"] = true;
            rv.Attributes["text"]    = ex.Message;
        }
    }
Example #2
0
File: Form.cs Project: radtek/EMIP
        public virtual JObject SignAuth(HttpContext context)
        {
            YZRequest request = new YZRequest(context);
            string    account = request.GetString("Account", null);
            string    pwd     = request.GetString("Password", null);

            using (BPMConnection cn = new BPMConnection())
            {
                cn.WebOpen();

                if (String.IsNullOrEmpty(account))
                {
                    account = cn.UID;
                }

                JObject rv = new JObject();
                rv[YZJsonProperty.success] = true;

                string token;
                if (BPMConnection.Authenticate(YZAuthHelper.BPMServerName, YZAuthHelper.BPMServerPort, account, pwd, out account, out token))
                {
                    rv["pass"] = true;
                }
                else
                {
                    rv["pass"] = false;
                }

                return(rv);
            }
        }
Example #3
0
        public virtual JObject ValidateCurrentUserPassword(HttpContext context)
        {
            YZRequest request = new YZRequest(context);
            string    pwd     = request.GetString("Password", null);
            string    uid     = YZAuthHelper.LoginUserAccount;

            using (BPMConnection cn = new BPMConnection())
            {
                cn.WebOpen();

                JObject rv = new JObject();
                rv[YZJsonProperty.success] = true;

                string token;
                if (BPMConnection.Authenticate(YZAuthHelper.BPMServerName, YZAuthHelper.BPMServerPort, uid, pwd, out uid, out token))
                {
                    rv["pass"] = true;
                }
                else
                {
                    rv["pass"] = false;
                }

                return(rv);
            }
        }
Example #4
0
        public virtual JObject LoginTrial(HttpContext context)
        {
            YZRequest request      = new YZRequest(context);
            bool      isapp        = request.GetBool("isapp");
            string    lang         = request.GetString("lang", "zh-chs");
            string    cordova      = request.GetString("cordova");
            string    model        = request.GetString("model");
            string    name         = request.GetString("name", model);
            string    platform     = request.GetString("platform");
            string    uuid         = request.GetString("uuid");
            string    version      = request.GetString("version");
            string    manufacturer = request.GetString("manufacturer");
            bool      isVirtual    = request.GetBool("isVirtual", false);
            string    serial       = request.GetString("serial");

            string uid = "99199";
            string pwd = "1";

            string realAccount = null;
            string token       = null;

            if (!BPMConnection.Authenticate(YZAuthHelper.BPMServerName, YZAuthHelper.BPMServerPort, uid, pwd, out realAccount, out token))
            {
                throw new Exception(Resources.YZStrings.Aspx_Login_Fail);
            }

            YZAuthHelper.SetAuthCookie(realAccount, token);
            YZAuthHelper.SetLangSession(YZCultureInfoParse.Parse(lang, YZCultureInfoParse.DefauleCultureInfo).LCID);
            YZAuthHelper.ClearLogoutFlag();

            JObject rv = this.GenLoginResult(realAccount, true);

            return(rv);
        }
Example #5
0
    private void SSOAuthLogin(OAuthToken TokenInfo)
    {
        #region string
        //string UID = System.Web.HttpContext.Current.Request.Params["UID"];
        //string Pwd = System.Web.HttpContext.Current.Request.Params["Pwd"];
        //string DesUrl = System.Web.HttpContext.Current.Request.Params["ReturnURL"];
        //string Redirect = "http://www.e.com/HandlerSSO.aspx?UID={0}&Pwd={1}&ReturnURL={2}";
        #endregion

        string UID      = TokenInfo.AccountID;
        string Pwd      = TokenInfo.PassWords;
        string DesUrl   = TokenInfo.ReturnURL;
        string Redirect = String.IsNullOrEmpty(TokenInfo.RedirectURL)
            ?  ConfigHelper.GetConfig("TokenCorrectRedirectURL")
            : TokenInfo.RedirectURL;

        if (!string.IsNullOrEmpty(UID))
        {
            string realAccount = null;
            if (BPMConnection.Authenticate(YZAuthHelper.BPMServerName, YZAuthHelper.BPMServerPort, UID, Pwd, out realAccount))
            {
                YZAuthHelper.SetAuthCookie(realAccount);
                YZAuthHelper.ClearLogoutFlag();

                if (!String.IsNullOrEmpty(DesUrl))
                {
                    Response.Redirect(DesUrl);
                }
                else
                {
                    Response.Redirect(Redirect.WithFormat(UID, Pwd, DesUrl));
                }
            }
            else
            {
                Response.Write("BPM验证失败");
            }
        }
        else
        {
            Response.Write("单点登录系统里UID为空");
        }
    }
Example #6
0
        private void SSO()
        {
            //try
            //{
            string UID    = System.Web.HttpContext.Current.Request.Params["UID"];
            string Pwd    = System.Web.HttpContext.Current.Request.Params["Pwd"];
            string DesUrl = System.Web.HttpContext.Current.Request.Params["ReturnURL"];

            if (!string.IsNullOrEmpty(UID))
            {
                string realAccount = null;
                if (BPMConnection.Authenticate(YZAuthHelper.BPMServerName, YZAuthHelper.BPMServerPort, UID, Pwd, out realAccount))
                {
                    YZAuthHelper.SetAuthCookie(realAccount);
                    YZAuthHelper.ClearLogoutFlag();

                    if (!String.IsNullOrEmpty(DesUrl))
                    {
                        Response.Redirect(DesUrl);
                    }
                    else
                    {
                        Response.Redirect("http://localhost/bpm");
                    }
                }
                else
                {
                    Response.Write("BPM验证失败");
                }
            }
            else
            {
                Response.Write("单点登录系统里uid为空");
            }
            //}
            //catch (Exception)
            //{

            //}
        }
Example #7
0
File: Form.cs Project: radtek/EMIP
        public virtual JObject SubmitAuth(HttpContext context)
        {
            YZRequest request = new YZRequest(context);
            int       stepid  = request.GetInt32("StepID", -1);
            string    pwd     = request.GetString("Password", null);

            using (BPMConnection cn = new BPMConnection())
            {
                cn.WebOpen();

                string uid = null;
                if (stepid != -1)
                {
                    BPMProcStep step = BPMProcStep.Load(cn, stepid);
                    uid = step.RecipientAccount;
                }
                else
                {
                    uid = cn.UID;
                }

                JObject rv = new JObject();
                rv[YZJsonProperty.success] = true;

                string token;
                if (BPMConnection.Authenticate(YZAuthHelper.BPMServerName, YZAuthHelper.BPMServerPort, uid, pwd, out uid, out token))
                {
                    rv["pass"] = true;
                }
                else
                {
                    rv["pass"] = false;
                }

                return(rv);
            }
        }
Example #8
0
        public void ProcessRequest(HttpContext context)
        {
            JsonItem rv       = new JsonItem();
            string   userid   = context.Request.Params["uid"];
            string   password = context.Request.Params["pwd"];
            string   isWeixIn = context.Request.Params["isWeixIn"];

            LoginUser loginUers = new LoginUser();

            String NetWork     = String.IsNullOrEmpty(context.Request.Params["NetWork"]) ? "" : context.Request.Params["NetWork"],
                   Phone       = String.IsNullOrEmpty(context.Request.Params["DevicePlatform"]) ? "" : context.Request.Params["DevicePlatform"],
                   DeviceName  = String.IsNullOrEmpty(context.Request.Params["DeviceName"]) ? "" : context.Request.Params["DeviceName"],
                   UUID        = String.IsNullOrEmpty(context.Request.Params["UUID"]) ? "" : context.Request.Params["UUID"],
                   Versions    = String.IsNullOrEmpty(context.Request.Params["Version"]) ? "Web客户端" : context.Request.Params["Version"],
                   strErrorMsg = String.Empty;


            try
            {
                if (String.IsNullOrEmpty(userid) /*|| String.IsNullOrEmpty(password)*/)
                {
                    if (String.IsNullOrWhiteSpace(isWeixIn))
                    {
                        throw new Exception(JosonStrings.Aspx_Login_EnterAccountTip);
                    }
                    else
                    {
                        throw new Exception("请关注微信服务号【创维数字移动办公】后,绑定你的域账号!");
                    }
                }

                string realAccount = null;
                if (!String.IsNullOrEmpty(isWeixIn))
                {
                    var isDegug = Convert.ToString(context.Request.Params["isDebug"]).ToLower().Equals("true");

                    if (context.Request.UserAgent.ToLower().Contains("micromessenger"))
                    {
                        realAccount = userid;
                        Versions    = "微信客户端";
                    }
                    else
                    {
                        if (!isDegug)
                        {
                            rv.Attributes["success"]      = false;
                            rv.Attributes["errorMessage"] = "试图非法登录!本次已经记录该操作!客户端仅提供微信绑定域用户使用" + DeviceName + Phone + NetWork;
                            context.Response.Write(rv.ToString());
                        }
                        else
                        {
                            realAccount = userid;
                            Versions    = "微信客户端";
                        }
                    }
                }
                else
                {
                    if (!BPMConnection.Authenticate(YZAuthHelper.BPMServerName, YZAuthHelper.BPMServerPort, userid, password, out realAccount))
                    {
                        throw new Exception(JosonStrings.Aspx_Login_Fail);
                    }
                }

                if (realAccount != null)
                {
                    YZAuthHelper.SetAuthCookie(realAccount);
                    YZAuthHelper.ClearLogoutFlag();


                    using (BPMConnection cn = new BPMConnection())
                    {
                        cn.WebOpen();
                        User user = User.FromAccount(cn, realAccount);

                        loginUers = cn.getLoginUser(userid, password, "LogIn", "logInOK", NetWork, Phone, UUID, DeviceName, Versions);

                        JsonItem juser = new JsonItem();
                        rv.Attributes["user"] = juser;

                        juser.Attributes["Account"] = user.Account;
                        string andriodPushService = WebConfigurationManager.AppSettings["AndroidPushService"];
                        juser.Attributes["AndroidPushService"] = String.IsNullOrEmpty(andriodPushService) ? "JPush" : andriodPushService;
                        juser.Attributes["HRID"]        = user.HRID;
                        juser.Attributes["DisplayName"] = user.DisplayName;
                        juser.Attributes["ShortName"]   = YZStringHelper.GetUserShortName(user.Account, user.DisplayName);
                        juser.Attributes["LongName"]    = YZStringHelper.GetUserFriendlyName(user.Account, user.DisplayName);
                        DateTime today = DateTime.Today;
                        juser.Attributes["LoginDate"] = String.Format("{0}年{1}月{2}日", today.Year, today.Month, today.Day);


                        juser.Attributes["NetWork"]    = NetWork;
                        juser.Attributes["Phone"]      = Phone;
                        juser.Attributes["UUID"]       = UUID;
                        juser.Attributes["DeviceName"] = DeviceName;
                    }

                    new SqlServerProvider(context).InsertLogInInfo(loginUers);
                    //System.Threading.Thread.Sleep(500);

                    rv.Attributes["success"] = true;
                    context.Response.Write(rv.ToString());
                }
            }
            catch (Exception exp)
            {
                YZEventLog log = new YZEventLog();
                log.WriteEntry(exp);

                loginUers.ErrorMsg = exp.Message;

                rv.Attributes["success"]      = false;
                rv.Attributes["errorMessage"] = exp.Message;
                context.Response.Write(rv.ToString());
            }
        }
Example #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (String.Compare(System.Web.Configuration.WebConfigurationManager.AppSettings["ShowMaintenancePage"], "true", true) == 0)
        {
            Response.Redirect("~/YZSoft/core/Maintenance/Default.aspx");
        }

        bool   webLogin = String.Compare(WebConfigurationManager.AppSettings["WebLoginEnable"], "false", true) == 0 ? false : true;
        bool   ntLogin  = String.Compare(WebConfigurationManager.AppSettings["NTLoginEnable"], "false", true) == 0 ? false : true;
        string action   = this.Request.Params["action"];

        if (action == "login")
        {
            string   type = this.Request.Params["type"];
            JsonItem rv   = new JsonItem();

            if (type == "NT") //NT登录
            {
                try
                {
                    if (this.NTLogin())
                    {
                        rv[YZJsonProperty.success] = true;
                        rv["text"] = Resources.YZStrings.Aspx_Login_Success;
                    }
                }
                catch (Exception exp)
                {
                    rv[YZJsonProperty.success] = false;
                    rv["text"] = exp.Message;
                }

                if (rv.Attributes.ContainsKey(YZJsonProperty.success))
                {
                    Response.Clear();
                    this.Response.Write(rv.ToString());
                    Response.End();
                }
                else
                {
                    this.Response.Clear();
                    this.Response.Status = "401 Unauthorized";
                    this.Response.AppendHeader("WWW-Authenticate", "NTLM");//Basic, Digest, NTLM, and Negotiate
                    this.Response.End();
                }
            }
            else //BPM 登录
            {
                string userid     = this.Request.Params["uid"];
                string password   = this.Request.Params["pwd"];
                string positionid = this.Request.Params["posid"];

                if (String.IsNullOrEmpty(userid) /*|| String.IsNullOrEmpty(password)*/)
                {
                    rv[YZJsonProperty.success] = false;
                    rv["text"] = Resources.YZStrings.Aspx_Login_EnterAccountTip;
                }
                else if (String.IsNullOrEmpty(positionid))
                {
                    rv[YZJsonProperty.success] = false;
                    rv["text"] = Resources.YZStrings.Aspx_Login_SelPosTip;
                }
                else
                {
                    try
                    {
                        string realAccount;
                        string token;
                        if (BPMConnection.Authenticate(YZAuthHelper.BPMServerName, YZAuthHelper.BPMServerPort, userid, password, out realAccount, out token))
                        {
                            YZAuthHelper.SetAuthCookie(realAccount, token);
                            YZAuthHelper.ClearLogoutFlag();

                            rv[YZJsonProperty.success] = true;
                            rv["text"] = Resources.YZStrings.Aspx_Login_Success;
                        }
                        else
                        {
                            rv[YZJsonProperty.success] = false;
                            rv["text"] = Resources.YZStrings.Aspx_Login_Fail;
                        }
                    }
                    catch (Exception exp)
                    {
                        YZEventLog log = new YZEventLog();
                        log.WriteEntry(exp);

                        rv[YZJsonProperty.success] = false;
                        rv["text"] = exp.Message;
                    }
                }

                Response.Clear();
                Response.Write(rv.ToString());
                Response.End();
            }
        }
        else if (action == "logout")
        {
            YZAuthHelper.SignOut();
            YZAuthHelper.SetLogoutFlag("logout", String.Empty);

            string ssoUrl = System.Configuration.ConfigurationManager.AppSettings["ssoUrl"];
            if (String.IsNullOrEmpty(ssoUrl))
            {
                ssoUrl = "~/"; //ssoUrl = "~/YZSoft/Login/";
            }
            this.Response.Redirect(ssoUrl, true);
        }
        else if (action == "changeuser")
        {
            YZAuthHelper.SignOut();
            YZAuthHelper.SetLogoutFlag("changeuser", YZAuthHelper.LoginUserAccount);
            string ssoUrl = System.Configuration.ConfigurationManager.AppSettings["ssoUrl"];
            if (String.IsNullOrEmpty(ssoUrl))
            {
                ssoUrl = "~/"; //ssoUrl = "~/YZSoft/Login/";
            }
            this.Response.Redirect(ssoUrl, true);
        }
        else
        {
            string ssoUrl = WebConfigurationManager.AppSettings["ssoUrl"];
            if (!String.IsNullOrEmpty(ssoUrl))
            {
                Response.Redirect(ssoUrl, true);
            }

            if (ntLogin && !webLogin) //仅NT登录
            {
                if (YZAuthHelper.BPMLogoutType != "logout" &&
                    YZAuthHelper.BPMLogoutType != "changeuser") //非登出情况下
                {
                    if (this.NTLogin())                         //NT登录成功
                    {
                        if (!String.IsNullOrEmpty(Request.QueryString["ReturnURL"]))
                        {
                            Response.Redirect(Request.QueryString["ReturnURL"]);
                        }
                        else
                        {
                            Response.Redirect("~/");
                        }

                        return;
                    }

                    if (String.IsNullOrEmpty(this.Request.ServerVariables["LOGON_USER"]))
                    {
                        this.Response.Clear();
                        this.Response.Status = "401 Unauthorized";
                        this.Response.AppendHeader("WWW-Authenticate", "NTLM");//Basic, Digest, NTLM, and Negotiate
                        this.Response.End();
                        return;
                    }
                }
            }

            //页标题
            this.Page.Title = System.Web.Configuration.WebConfigurationManager.AppSettings["CompanyInfoLoginPageTitle"];
            if (String.IsNullOrEmpty(this.Page.Title))
            {
                this.Page.Title = Resources.YZStrings.Aspx_Login_Title;
            }

            //根据启动程序应用Css
            string startApp = System.Web.Configuration.WebConfigurationManager.AppSettings["StartApp"];
            if (String.IsNullOrEmpty(startApp))
            {
                startApp = "YZApp";
            }

            this._litLoginCss.Text = String.Format("<link href=\"../../../{0}/Styles/login.css\" rel=\"stylesheet\" type=\"text/css\" />", startApp);

            //显示文字
            this._litBoxCaption.Text    = Resources.YZStrings.Aspx_Login_BoxCaption;
            this._litAccount.Text       = Resources.YZStrings.Aspx_Login_Account;
            this._lnkRegNewAccount.Text = Resources.YZStrings.Aspx_Login_RegNewAccount;
            this._litPwd.Text           = Resources.YZStrings.Aspx_Login_Pwd;
            this._lnkForgotPwd.Text     = Resources.YZStrings.Aspx_Login_ForgotPwd;
            this._btnLogin.Value        = Resources.YZStrings.Aspx_Login_BtnLogin;
            this._btnNTLogin.Value      = Resources.YZStrings.Aspx_Login_BtnNTLogin;

            string[]        strLcids = Resources.YZStrings.All_Languages.Split(new char[] { ',', ';' });
            Type            resType  = typeof(Resources.YZStrings);
            ResourceManager mgr      = new ResourceManager(resType.FullName, resType.Assembly);
            List <String>   langs    = new List <string>();
            foreach (string strLcid in strLcids)
            {
                string resName  = "All_Languages_" + strLcid;
                string langName = mgr.GetString(resName);
                bool   current  = String.Compare(langName, Resources.YZStrings.All_Languages_Cur, 0) == 0;

                langs.Add(String.Format("<a href=\"#\" class=\"yz-login-lang-item {0}\" onclick=\"changeLanguage('{1}');\">{2}</a>", current ? "yz-login-lang-item-selected" : "", strLcid, langName));
            }
            this._litChangeLang.Text = String.Join("<span class=\"yz-login-lang-sp\">|</span>", langs.ToArray());

            //关闭用户注册,忘记密码链接
            //this._lnkRegNewAccount.Enabled = false;
            //this._lnkForgotPwd.Enabled = false;
            this._lnkRegNewAccount.Visible = false;
            this._lnkForgotPwd.Visible     = false;

            this._litStep2Caption.Text = Resources.YZStrings.Aspx_Login_Step2_BoxCaption;
            this._litStep2Msg.Text     = String.Format(Resources.YZStrings.Aspx_Login_Step2_Msg, "<span class=\"point\">●</span>");

            this._litStep1Caption.Text         = Resources.YZStrings.Aspx_Login_Step1_BoxCaption;
            this._litStep1Msg.Text             = Resources.YZStrings.Aspx_Login_Step1_Msg;
            this._litStep1InsCurStep0.Text     = Resources.YZStrings.Aspx_Login_Step1_Install_CurStep;
            this._litStep1InsCurStep1.Text     = Resources.YZStrings.Aspx_Login_Step1_Install_CurStep;
            this._litStep1InsCurStep2.Text     = Resources.YZStrings.Aspx_Login_Step1_Install_CurStep;
            this._litStep1InsCurStep3.Text     = Resources.YZStrings.Aspx_Login_Step1_Install_CurStep;
            this._litStep1InsCurStep4.Text     = Resources.YZStrings.Aspx_Login_Step1_Install_CurStep;
            this._litStep1NotInstalled.Text    = Resources.YZStrings.Aspx_Login_Step1_Install_NotInstalled;
            this._litStep1InstallNow.Text      = Resources.YZStrings.Aspx_Login_Step1_Install_InstallNow;
            this._litStep1Installing.Text      = Resources.YZStrings.Aspx_Login_Step1_Install_Installing;
            this._litStep1Installing1.Text     = Resources.YZStrings.Aspx_Login_Step1_Install_Installing;
            this._litStep1PlsWaiting.Text      = Resources.YZStrings.Aspx_Login_Step1_Install_PlsWaiting;
            this._litStep1InstallFinished.Text = Resources.YZStrings.Aspx_Login_Step1_Install_InstallFinished;
            this._litStep1CheckAgain.Text      = Resources.YZStrings.Aspx_Login_Step1_Install_CheckAgain;
            this._litStep1InstallFailed.Text   = Resources.YZStrings.Aspx_Login_Step1_Install_InstallFailed;
            this._litStep1Retry.Text           = Resources.YZStrings.Aspx_Login_Step1_Install_Retry;
            this._litStep1InstallSucceed.Text  = Resources.YZStrings.Aspx_Login_Step1_Install_InstallSucceed;
            this._litStep1LoginContinue.Text   = Resources.YZStrings.Aspx_Login_Step1_Login_Continue;
            this._litStep1Ignore.Text          = Resources.YZStrings.Aspx_Login_Step1_Ignore;

            this._litStep0Caption.Text         = Resources.YZStrings.Aspx_Login_Step0_BoxCaption;
            this._litStep0Msg.Text             = Resources.YZStrings.Aspx_Login_Step0_Msg;
            this._litStep0Skip.Text            = Resources.YZStrings.Aspx_Login_Step0_Skip;
            this._litStep0Skip1.Text           = Resources.YZStrings.Aspx_Login_Step0_Skip;
            this._litStep0DownloadBrowser.Text = Resources.YZStrings.Aspx_Login_Step0_DownloadBrowser;

            this._downloadXP.Text    = Resources.YZStrings.Aspx_Login_Step0_Download;
            this._downloadVista.Text = Resources.YZStrings.Aspx_Login_Step0_Download;
            this._download2003.Text  = Resources.YZStrings.Aspx_Login_Step0_Download;
            this._downloadMore.Text  = Resources.YZStrings.Aspx_Login_Step0_Download_More;

            //JS文字
            JsonItem jsonStrings = new JsonItem();
            jsonStrings.Attributes.Add("Account", YZAuthHelper.LoginUserAccount);
            jsonStrings.Attributes.Add("SelPos", Resources.YZStrings.Aspx_Login_SelPos);
            jsonStrings.Attributes.Add("SelPosTip", Resources.YZStrings.Aspx_Login_SelPosTip);
            jsonStrings.Attributes.Add("EnterAccountTip", Resources.YZStrings.Aspx_Login_EnterAccountTip);
            jsonStrings.Attributes.Add("EnterPwdTip", Resources.YZStrings.Aspx_Login_EnterPwdTip);
            jsonStrings.Attributes.Add("BrowserNameOpera", Resources.YZStrings.Aspx_BrowserNameOpera);
            jsonStrings.Attributes.Add("BrowserNameSafari", Resources.YZStrings.Aspx_BrowserNameSafari);
            jsonStrings.Attributes.Add("BrowserNameGoogle", Resources.YZStrings.Aspx_BrowserNameGoogle);
            jsonStrings.Attributes.Add("BrowserNameFirefox", Resources.YZStrings.Aspx_BrowserNameFirefox);
            jsonStrings.Attributes.Add("BrowserNameOther", Resources.YZStrings.Aspx_BrowserNameOther);
            jsonStrings.Attributes.Add("BrowserWarning", Resources.YZStrings.Aspx_Login_BrowserWarning);
            jsonStrings.Attributes.Add("Unknow", Resources.YZStrings.Aspx_Login_Unknow);
            jsonStrings.Attributes.Add("HttpErr", Resources.YZStrings.Aspx_Login_HttpErr);

            HtmlGenericControl jsstrs = new HtmlGenericControl("script");
            jsstrs.Attributes["type"] = "text/javascript";
            jsstrs.InnerHtml          = String.Format("var Strings = {0}", jsonStrings.ToString());
            this.Page.Header.Controls.AddAt(1, jsstrs);

            //地图信息
            JArray factorys;
            using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider)
            {
                using (IDbConnection cn = provider.OpenConnection())
                {
                    factorys = provider.GetFactorys(cn);
                }
            }

            string returnUrl = String.Empty;
            if (!String.IsNullOrEmpty(Request.QueryString["ReturnURL"]))
            {
                returnUrl = this.ResolveClientUrl(Request.QueryString["ReturnURL"]);
            }
            else
            {
                returnUrl = this.ResolveClientUrl("~/");
            }

            HtmlGenericControl js = new HtmlGenericControl("script");
            js.Attributes["type"] = "text/javascript";
            js.InnerHtml          = "var _FactoryData=" + factorys.ToString() + ";\n" +
                                    "var returnUrl=\"" + YZUtility.EncodeJsString(returnUrl) + "\";";

            this.Page.Header.Controls.AddAt(1, js);

            if (!webLogin)
            {
                this._txtUserId.Enabled        = false;
                this._txtPassword.Enabled      = false;
                this._txtUserId.CssClass       = "input input-disabled";
                this._txtPassword.CssClass     = "input input-disabled";
                this._lnkRegNewAccount.Enabled = false;
                this._lnkForgotPwd.Enabled     = false;
                this._btnLogin.Disabled        = true;
            }
            if (!ntLogin)
            {
                this._btnNTLogin.Disabled = true;
            }
        }
    }
Example #10
0
        public virtual JObject Login(HttpContext context)
        {
            YZRequest request             = new YZRequest(context);
            string    lang                = request.GetString("lang", "zh-chs");
            string    uid                 = request.GetString("uid");
            string    pwd                 = request.GetString("pwd", null);
            bool      isapp               = request.GetBool("isapp");
            string    cordova             = request.GetString("cordova");
            string    model               = request.GetString("model");
            string    name                = request.GetString("name", model);
            string    platform            = request.GetString("platform");
            string    uuid                = request.GetString("uuid");
            string    version             = request.GetString("version");
            string    manufacturer        = request.GetString("manufacturer");
            bool      isVirtual           = request.GetBool("isVirtual", false);
            string    serial              = request.GetString("serial");
            bool      validationPanelShow = request.GetBool("validationPanelShow");
            string    smsGuid             = request.GetString("smsGuid", null);
            string    vcode               = request.GetString("vcode", null);
            string    keystore            = request.GetString("keystore", null);

            //用私钥解密
            if (!String.IsNullOrEmpty(keystore))
            {
                string privateKey = (string)YZTempStorageManager.CurrentStore.Load(keystore);

                RSACryptoServiceProvider rsaProvider = new RSACryptoServiceProvider(1024);
                rsaProvider.FromXmlString(privateKey);

                uid = System.Text.Encoding.UTF8.GetString(rsaProvider.Decrypt(Convert.FromBase64String(uid), false));
                pwd = System.Text.Encoding.UTF8.GetString(rsaProvider.Decrypt(Convert.FromBase64String(pwd), false));
            }

            Device  device = null;
            SMS     sms    = null;
            JObject rv;

            if (isapp)
            {
                using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider)
                {
                    using (IDbConnection cn = provider.OpenConnection())
                    {
                        device = DeviceManager.TryGetDevice(provider, cn, uid, uuid);
                    }
                }

                //设备禁用
                if (device != null && device.Disabled)
                {
                    rv = new JObject();
                    rv[YZJsonProperty.success] = false;
                    rv["prompt"] = true;
                    rv[YZJsonProperty.errorMessage] = Resources.YZMobile.Aspx_Auth_DeviceDisabled;
                    return(rv);
                }

                //账号保护
                if (device == null)
                {
                    bool IsAppLoginProtected;
                    using (BPMConnection cn = new BPMConnection())
                    {
                        cn.WebOpenAnonymous();
                        IsAppLoginProtected = User.IsAppLoginProtected(cn, uid);
                    }

                    if (IsAppLoginProtected)
                    {
                        if (!validationPanelShow)
                        {
                            rv = new JObject();
                            rv[YZJsonProperty.success]      = false;
                            rv["needSmsValidation"]         = true;
                            rv[YZJsonProperty.errorMessage] = Resources.YZMobile.Aspx_Auth_StrangerDevice;
                            return(rv);
                        }

                        if (String.IsNullOrEmpty(smsGuid))
                        {
                            throw new Exception(Resources.YZMobile.Aspx_Auth_GetValidationCodeFirst);
                        }

                        using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider)
                        {
                            using (IDbConnection cn = provider.OpenConnection())
                            {
                                sms = SMSManager.TryGetSMS(provider, cn, smsGuid);
                            }
                        }

                        if (sms == null)
                        {
                            throw new Exception(Resources.YZMobile.Aspx_Auth_GetValidationCodeAgain);
                        }

                        if (sms.ValidationCode != vcode)
                        {
                            throw new Exception(Resources.YZMobile.Aspx_Auth_IncorrectValidationCode);
                        }

                        if (sms.ExpireDate < DateTime.Now)
                        {
                            throw new Exception(Resources.YZMobile.Aspx_Auth_GetValidationCodeAgain);
                        }
                    }
                }
            }

            if (String.IsNullOrEmpty(uid) /*|| String.IsNullOrEmpty(password)*/)
            {
                throw new Exception(Resources.YZStrings.Aspx_Login_EnterAccountTip);
            }

            string realAccount = null;
            string token       = null;

            if (!BPMConnection.Authenticate(YZAuthHelper.BPMServerName, YZAuthHelper.BPMServerPort, uid, pwd, out realAccount, out token))
            {
                throw new Exception(Resources.YZStrings.Aspx_Login_Fail);
            }

            YZAuthHelper.SetAuthCookie(realAccount, token);
            YZAuthHelper.SetLangSession(YZCultureInfoParse.Parse(lang, YZCultureInfoParse.DefauleCultureInfo).LCID);
            YZAuthHelper.ClearLogoutFlag();

            rv = this.GenLoginResult(realAccount, false);

            //登录成功后处理
            if (isapp)
            {
                using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider)
                {
                    using (IDbConnection cn = provider.OpenConnection())
                    {
                        if (device != null)
                        {
                            device.LastLogin = DateTime.Now;
                            DeviceManager.Update(provider, cn, device);
                        }
                        else
                        {
                            device             = new Device();
                            device.Account     = realAccount;
                            device.UUID        = uuid;
                            device.Name        = name;
                            device.Model       = model;
                            device.Description = String.Format("{0} {1} {2} {3}", manufacturer, model, platform, version);
                            device.Disabled    = false;
                            device.RegisterAt  = DateTime.Now;
                            device.LastLogin   = device.RegisterAt;
                            DeviceManager.Insert(provider, cn, device);
                        }

                        if (sms != null)
                        {
                            SMSManager.DeleteSMS(provider, cn, sms.ItemGUID);
                        }
                    }
                }
            }

            return(rv);
        }
Example #11
0
    public void Login()
    {
        YZRequest request  = new YZRequest(this.Context);
        string    uid      = request.GetString("uid", null);
        string    pwd      = request.GetString("uep", null);
        string    keystore = request.GetString("keystore", null);

        JObject rv = new JObject();

        if (String.IsNullOrEmpty(uid) /*|| String.IsNullOrEmpty(pwd)*/)
        {
            rv[YZJsonProperty.success] = false;
            rv["errorMessage"]         = Resources.YZStrings.Aspx_Login_EnterAccountTip;
        }
        else
        {
            try
            {
                string realAccount;
                string token;

                //用私钥解密
                if (!String.IsNullOrEmpty(keystore))
                {
                    string privateKey = (string)YZTempStorageManager.CurrentStore.Load(keystore);

                    RSACryptoServiceProvider rsaProvider = new RSACryptoServiceProvider(1024);
                    rsaProvider.FromXmlString(privateKey);

                    uid = System.Text.Encoding.UTF8.GetString(rsaProvider.Decrypt(Convert.FromBase64String(uid), false));
                    pwd = System.Text.Encoding.UTF8.GetString(rsaProvider.Decrypt(Convert.FromBase64String(pwd), false));
                }

                if (BPMConnection.Authenticate(YZAuthHelper.BPMServerName, YZAuthHelper.BPMServerPort, uid, pwd, out realAccount, out token))
                {
                    YZAuthHelper.SetAuthCookie(realAccount, token);
                    YZAuthHelper.ClearLogoutFlag();

                    rv[YZJsonProperty.success] = true;
                    rv["errorMessage"]         = Resources.YZStrings.Aspx_Login_Success;
                }
                else
                {
                    rv[YZJsonProperty.success] = false;
                    rv["errorMessage"]         = Resources.YZStrings.Aspx_Login_Fail;
                }
            }
            catch (Exception exp)
            {
                YZEventLog log = new YZEventLog();
                log.WriteEntry(exp);

                rv[YZJsonProperty.success] = false;
                rv["errorMessage"]         = exp.Message;
            }
        }

        this.Response.Clear();
        this.Response.Write(rv.ToString(Formatting.Indented, YZJsonHelper.Converters));
        this.Response.End();
    }