Esempio n. 1
0
    /// <summary>削除ボタン</summary>
    /// <param name="fxEventArgs">イベントハンドラの共通引数</param>
    /// <returns>URL</returns>
    protected string UOC_btnDelete_Click(FxEventArgs fxEventArgs)
    {
        // 引数クラスを生成
        _3TierParameterValue parameterValue = new _3TierParameterValue(
            this.ContentPageFileNoEx, fxEventArgs.ButtonID, "DeleteRecord",
            (string)Session["DAP"], (MyUserInfo)UserInfoHandle.GetUserInformation());

        // テーブル
        parameterValue.TableName = "Products";

        // 主キーとタイムスタンプ列
        // 主キー列
        parameterValue.AndEqualSearchConditions = (Dictionary <string, object>)Session["PrimaryKeyAndTimeStamp"];
        // タイムスタンプ列

        // B層を生成
        _3TierEngine b = new _3TierEngine();

        // データ取得処理を実行
        _3TierReturnValue returnValue =
            (_3TierReturnValue)b.DoBusinessLogic(
                (BaseParameterValue)parameterValue, DbEnum.IsolationLevelEnum.ReadCommitted);

        // 結果表示
        this.lblResult.Text = returnValue.Obj.ToString() + "件削除しました。";

        // 画面遷移しない。
        return(string.Empty);
    }
Esempio n. 2
0
        /// <summary>ログイン</summary>
        /// <param name="fxEventArgs">Event Handlerの共通引数</param>
        /// <returns>URL</returns>
        protected string UOC_btnButton1_Click(FxEventArgs fxEventArgs)
        {
            // ここで、入力されたユーザIDと、パスワードをチェックし、ユーザ認証する。

            if (!string.IsNullOrEmpty(this.txtUserID.Text))  // 現時点では、全て(空文字以外)認証する。
            {
                // 認証か完了した場合、認証チケットを生成し、元のページにRedirectする。
                // 第2引数は、「クライアントがCookieを永続化(ファイルとして保存)するかどうか。」
                // を設定する引数であるが、セキュリティを考慮して、falseの設定を勧める。
                FormsAuthentication.RedirectFromLoginPage(this.txtUserID.Text, false);

                // 認証情報を保存する。
                MyUserInfo ui = new MyUserInfo(this.txtUserID.Text, Request.UserHostAddress);
                UserInfoHandle.SetUserInformation(ui);
            }
            else
            {
                // 認証に失敗した場合は、Messageを表示する
                this.lblMessage.Text = "認証に失敗しました。ユーザIDか、パスワードが間違っています。";

                // Session消去
                this.FxSessionAbandon();
            }

            // 画面遷移はしない(基盤に任せるため)。
            return(string.Empty);
        }
Esempio n. 3
0
 /// <summary>
 /// 更新用户信息
 /// </summary>
 /// <param name="model">用户资料</param>
 /// <returns></returns>
 public QssResult QssUpdateUserInfo(QssSicauLoginHelper login, UserType type, out User user)
 {
     // 判断学生还是教师
     if (type == UserType.S)
     {
         string[] _stuInfo = login.GetStuInfo();
         if (_stuInfo.Length == 0)
         {
             QssLogHelper.Log("获取学生信息失败", "学生登录时,通过模拟登录教务网获取学生信息,但是并没有获取成功!", QssLogType.Info);
             user = null;
             return(QssResult.Fail);
         }
         var stuInfo = new UserInfoHandle(_stuInfo);
         return(QssUpdateUserInfo(stuInfo, out user));
     }
     else
     {
         string[] _thInfo = login.GetThInfo();
         if (_thInfo.Length == 0)
         {
             QssLogHelper.Log("获取教师信息失败", "教师登录时,通过模拟登录教务网获取教师信息,但是并没有获取成功!", QssLogType.Info);
             user = null;
             return(QssResult.Fail);
         }
         var thInfo = new UserInfoHandle(_thInfo);
         return(QssUpdateUserInfo(thInfo, out user));
     }
 }
Esempio n. 4
0
        public async Task <ActionResult> OAuthAuthorizationCodeGrantClient(string code, string state)
        {
            try
            {
                OAuth2AndOIDCClient.HttpClient = new HttpClient();
                string response = "";

                if (state == this.State) // CSRF(XSRF)対策のstateの検証は重要
                {
                    response = await OAuth2AndOIDCClient.GetAccessTokenByCodeAsync(
                        new Uri("http://localhost:63359/MultiPurposeAuthSite/OAuthBearerToken"),
                        OAuth2AndOIDCParams.ClientID, OAuth2AndOIDCParams.ClientSecret,
                        HttpUtility.HtmlEncode("http://localhost:63877/SPA_Sample/Home/OAuthAuthorizationCodeGrantClient"), code);

                    // 汎用認証サイトはOIDCをサポートしたのでid_tokenを取得し、検証可能。
                    Base64UrlTextEncoder        base64UrlEncoder = new Base64UrlTextEncoder();
                    Dictionary <string, string> dic = JsonConvert.DeserializeObject <Dictionary <string, string> >(response);

                    // id_tokenの検証コード
                    if (dic.ContainsKey("id_token"))
                    {
                        string id_token = dic["id_token"];

                        string        sub    = "";
                        List <string> roles  = null;
                        List <string> scopes = null;
                        JObject       jobj   = null;

                        if (JwtToken.Verify(id_token, out sub, out roles, out scopes, out jobj) &&
                            jobj["nonce"].ToString() == this.Nonce)
                        {
                            // ログインに成功

                            // /userinfoエンドポイントにアクセスする場合
                            response = await OAuth2AndOIDCClient.CallUserInfoEndpointAsync(
                                new Uri("http://localhost:63359/MultiPurposeAuthSite/userinfo"), dic["access_token"]);

                            FormsAuthentication.RedirectFromLoginPage(sub, false);
                            MyUserInfo ui = new MyUserInfo(sub, Request.UserHostAddress);
                            UserInfoHandle.SetUserInformation(ui);

                            return(new EmptyResult());
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                }

                // ログインに失敗
                return(RedirectToAction("Login"));
            }
            finally
            {
                this.ClearExLoginsParams();
            }
        }
Esempio n. 5
0
        public ActionResult Login(LoginViewModel model)
        {
            if (!string.IsNullOrEmpty(model.UserName))
            {
                // 認証か完了した場合、認証チケットを生成し、元のページにRedirectする。
                // 第2引数は、「クライアントがCookieを永続化(ファイルとして保存)するかどうか。」
                // を設定する引数であるが、セキュリティを考慮して、falseの設定を勧める。
                FormsAuthentication.RedirectFromLoginPage(model.UserName, false);

                // 認証情報を保存する。
                MyUserInfo ui = new MyUserInfo(model.UserName, Request.UserHostAddress);
                UserInfoHandle.SetUserInformation(ui);

                //基盤に任せるのでリダイレクトしない。
                //return this.Redirect(ReturnUrl);
                return(new EmptyResult());
            }
            else
            {
                // ユーザー認証 失敗
                this.ModelState.AddModelError(string.Empty, "指定されたユーザー名またはパスワードが正しくありません。");

                // Session消去
                this.FxSessionAbandon();

                // ポストバック的な
                return(this.View(model));
            }
        }
Esempio n. 6
0
    /// <summary>バッチ更新ボタン</summary>
    /// <param name="fxEventArgs">イベントハンドラの共通引数</param>
    /// <returns>URL</returns>
    protected string UOC_btnBatUpd_Click(FxEventArgs fxEventArgs)
    {
        // 引数クラスを生成
        _3TierParameterValue parameterValue = new _3TierParameterValue(
            this.ContentPageFileNoEx, fxEventArgs.ButtonID, "BatchUpdate",
            (string)Session["DAP"], (MyUserInfo)UserInfoHandle.GetUserInformation());

        // テーブル
        parameterValue.TableName = "Products";

        // 主キーとタイムスタンプ列
        parameterValue.AndEqualSearchConditions = new Dictionary <string, object>();
        parameterValue.AndEqualSearchConditions.Add("ProductID", "");

        // DataTableを設定
        parameterValue.Obj = (DataTable)Session["SearchResult"];

        // B層を生成
        _3TierEngine b = new _3TierEngine();

        // データ取得処理を実行
        _3TierReturnValue returnValue =
            (_3TierReturnValue)b.DoBusinessLogic(
                (BaseParameterValue)parameterValue, DbEnum.IsolationLevelEnum.ReadCommitted);

        // 結果表示
        //this.lblResult.Text = returnValue.Obj.ToString() + "件更新しました。";

        // 画面遷移しない。
        return(string.Empty);
    }
        /// <summary>ユーザ情報を取得する</summary>
        /// <returns>ユーザ情報</returns>
        private MyUserInfo GetUserInfo()
        {
            MyUserInfo ui = (MyUserInfo)UserInfoHandle.GetUserInformation();

            // 再取得する。
            if (ui == null)
            {
                // Cookie認証チケット
                HttpCookie authCookie
                    = Context.Request.Cookies["formauth"];

                if (authCookie == null) // 認証チケットがない場合
                {
                    // ダミーのユーザ情報を設定する。
                    ui = new MyUserInfo("未認証", Request.UserHostAddress);
                }
                else // 認証チケットがある場合
                {
                    // ユーザ情報を再取得する。

                    // 認証チケット
                    FormsAuthenticationTicket authTicket
                        = FormsAuthentication.Decrypt(authCookie.Value);

                    // ユーザ名を復元
                    ui = new MyUserInfo(authTicket.Name, Request.UserHostAddress);
                }
            }

            return(ui);
        }
Esempio n. 8
0
        public async Task <IActionResult> Login(LoginViewModel model)
        {
            if (!Request.Form.Keys.Any(x => x == "external"))
            {
                // 通常ログイン
                if (ModelState.IsValid)
                {
                    if (!string.IsNullOrEmpty(model.UserName))
                    {
                        // 認証情報を作成する。
                        List <Claim> claims = new List <Claim>();
                        claims.Add(new Claim(ClaimTypes.Name, model.UserName));

                        // 認証情報を保存する。
                        ClaimsIdentity  userIdentity  = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                        ClaimsPrincipal userPrincipal = new ClaimsPrincipal(userIdentity);

                        // サイン アップする。
                        await AuthenticationHttpContextExtensions.SignInAsync(
                            this.HttpContext, CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal);

                        // 認証情報を保存する。
                        MyUserInfo ui = new MyUserInfo(model.UserName, (new GetClientIpAddress()).GetAddress());
                        UserInfoHandle.SetUserInformation(ui);

                        //基盤に任せるのでリダイレクトしない。
                        return(View(model));
                    }
                    else
                    {
                        // ユーザー認証 失敗
                        this.ModelState.AddModelError(string.Empty, "指定されたユーザー名またはパスワードが正しくありません。");
                    }
                }
                else
                {
                    // LoginViewModelの検証に失敗
                }

                // Session消去
                //this.FxSessionAbandon();

                // ポストバック的な
                return(this.View(model));
            }
            else
            {
                // 外部ログイン
                return(Redirect(string.Format(
                                    "https://localhost:44300/MultiPurposeAuthSite/authorize"
                                    + "?client_id=" + OAuth2AndOIDCParams.ClientID
                                    + "&response_type=code"
                                    + "&scope=profile%20email%20phone%20address%20openid"
                                    + "&state={0}"
                                    + "&nonce={1}"
                                    + "&prompt=none",
                                    this.State, this.Nonce)));
            }
        }
Esempio n. 9
0
        /// <summary>Page_Load</summary>
        /// <param name="sender">object</param>
        /// <param name="e">EventArgs</param>
        protected async void Page_Load(object sender, EventArgs e)
        {
            string code  = Request.QueryString["code"];
            string state = Request.QueryString["state"];

            try
            {
                string response = "";

                if (state == this.State) // CSRF(XSRF)対策のstateの検証は重要
                {
                    response = await OAuth2AndOIDCClient.GetAccessTokenByCodeAsync(
                        new Uri("https://localhost:44300/MultiPurposeAuthSite/token"),
                        OAuth2AndOIDCParams.ClientID, OAuth2AndOIDCParams.ClientSecret,
                        HttpUtility.HtmlEncode("http://localhost:9999/WebForms_Sample/Aspx/Auth/OAuthAuthorizationCodeGrantClient.aspx"), code);

                    // 汎用認証サイトはOIDCをサポートしたのでid_tokenを取得し、検証可能。
                    Base64UrlTextEncoder        base64UrlEncoder = new Base64UrlTextEncoder();
                    Dictionary <string, string> dic = JsonConvert.DeserializeObject <Dictionary <string, string> >(response);

                    string  sub   = "";
                    string  nonce = "";
                    JObject jobj  = null;

                    // id_tokenの検証
                    if (IdToken.Verify(dic["id_token"], dic["access_token"],
                                       code, state, out sub, out nonce, out jobj) && nonce == this.Nonce)
                    {
                        // ログインに成功
                        // /userinfoエンドポイントにアクセスする場合
                        response = await OAuth2AndOIDCClient.GetUserInfoAsync(
                            new Uri("https://localhost:44300/MultiPurposeAuthSite/userinfo"), dic["access_token"]);

                        FormsAuthentication.RedirectFromLoginPage(sub, false);
                        MyUserInfo ui = new MyUserInfo(sub, Request.UserHostAddress);
                        UserInfoHandle.SetUserInformation(ui);

                        return;
                    }
                    else
                    {
                    }
                }
                else
                {
                }

                // ResolveClientUrlがInvalidOperationExceptionを吐くので...
                //// ログインに失敗
                //Response.Redirect("../Start/login.aspx");
            }
            finally
            {
                this.ClearExLoginsParams();
            }
        }
Esempio n. 10
0
        public ActionResult Login(LoginViewModel model)
        {
            if (!Request.Form.AllKeys.Any(x => x == "external"))
            {
                // 通常ログイン
                if (ModelState.IsValid)
                {
                    if (!string.IsNullOrEmpty(model.UserName))
                    {
                        // 認証か完了した場合、認証チケットを生成し、元のページにRedirectする。
                        // 第2引数は、「クライアントがCookieを永続化(ファイルとして保存)するかどうか。」
                        // を設定する引数であるが、セキュリティを考慮して、falseの設定を勧める。
                        FormsAuthentication.RedirectFromLoginPage(model.UserName, false);

                        // 認証情報を保存する。
                        MyUserInfo ui = new MyUserInfo(model.UserName, Request.UserHostAddress);
                        UserInfoHandle.SetUserInformation(ui);

                        //基盤に任せるのでリダイレクトしない。
                        //return this.Redirect(ReturnUrl);
                        return(new EmptyResult());
                    }
                    else
                    {
                        // ユーザー認証 失敗
                        this.ModelState.AddModelError(string.Empty, "指定されたユーザー名またはパスワードが正しくありません。");
                    }
                }
                else
                {
                    // LoginViewModelの検証に失敗
                }

                // Session消去
                this.FxSessionAbandon();

                // ポストバック的な
                return(this.View(model));
            }
            else
            {
                // 外部ログイン
                return(Redirect(string.Format(
                                    "http://localhost:63359/MultiPurposeAuthSite/Account/OAuthAuthorize"
                                    + "?client_id=" + OAuth2AndOIDCParams.ClientID
                                    + "&response_type=code"
                                    + "&scope=profile%20email%20phone%20address%20openid"
                                    + "&state={0}"
                                    + "&nonce={1}"
                                    + "&prompt=none",
                                    this.State, this.Nonce)));
            }
        }
        /// <summary>ユーザ情報を取得する</summary>
        private async Task GetUserInfo()
        {
            // セッションステートレス対応
            if (MyHttpContext.Current.Session == null)
            {
                // SessionがOFFの場合
            }
            else
            {
                // 取得を試みる。
                this.UserInfo = UserInfoHandle.GetUserInformation <MyUserInfo>();

                // nullチェック
                if (this.UserInfo == null)
                {
                    AuthenticateResult authenticateInfo =
                        await AuthenticationHttpContextExtensions.AuthenticateAsync(
                            MyHttpContext.Current, CookieAuthenticationDefaults.AuthenticationScheme);

                    //await MyHttpContext.Current.Authentication.GetAuthenticateInfoAsync(
                    //    CookieAuthenticationDefaults.AuthenticationScheme); // 古い

                    //System.Threading.Thread.CurrentPrincipal.Identity.Name; // .NET Framework

                    string userName = authenticateInfo.Principal?.Identity?.Name; // null 条件演算子

                    if (string.IsNullOrEmpty(userName))
                    {
                        // 未認証状態
                        this.UserInfo = new MyUserInfo("未認証", (new GetClientIpAddress()).GetAddress());
                    }
                    else
                    {
                        // 認証状態
                        this.UserInfo = new MyUserInfo(userName, (new GetClientIpAddress()).GetAddress());

                        // 必要に応じて認証チケットのユーザ名からユーザ情報を復元する。
                        // ★ 必要であれば、他の業務共通引継ぎ情報などをロードする。
                        // ・・・

                        // 復元したユーザ情報をセット
                        UserInfoHandle.SetUserInformation(this.UserInfo);
                    }
                }
            }
        }
Esempio n. 12
0
        /// <summary>ユーザ情報を取得する</summary>
        /// <remarks>他から呼び出し可能に変更(static)</remarks>
        public static MyUserInfo GetUserInfo2()
        {
            MyUserInfo userInfo = null;

            // セッションステートレス対応
            if (HttpContext.Current.Session == null)
            {
                // SessionがOFFの場合
            }
            else
            {
                // 取得を試みる。
                userInfo = (MyUserInfo)UserInfoHandle.GetUserInformation();
            }

            // nullチェック
            if (userInfo == null)
            {
                // nullの場合、仮の値を生成 / 設定する。
                string userName = System.Threading.Thread.CurrentPrincipal.Identity.Name;

                if (userName == null || userName == "")
                {
                    // 未認証状態
                    userInfo = new MyUserInfo("未認証", HttpContext.Current.Request.UserHostAddress);
                }
                else
                {
                    // 認証状態
                    userInfo = new MyUserInfo(userName, HttpContext.Current.Request.UserHostAddress);
                    // 必要に応じて認証チケットの
                    // ユーザ名からユーザ情報を復元する。
                }
            }
            else
            {
                // nullで無い場合、取得した値を設定する。
            }

            // ★ 必要であれば、他の業務共通引継ぎ情報などをロードする。

            // 値を戻す。
            return(userInfo);
        }
Esempio n. 13
0
    /// <summary>更新ボタン</summary>
    /// <param name="fxEventArgs">イベントハンドラの共通引数</param>
    /// <returns>URL</returns>
    protected string UOC_btnUpdate_Click(FxEventArgs fxEventArgs)
    {
        // 引数クラスを生成
        _3TierParameterValue parameterValue = new _3TierParameterValue(
            this.ContentPageFileNoEx, fxEventArgs.ButtonID, "UpdateRecord",
            (string)Session["DAP"], (MyUserInfo)UserInfoHandle.GetUserInformation());

        // テーブル
        parameterValue.TableName = "Products";

        // 主キーとタイムスタンプ列
        // 主キー列
        parameterValue.AndEqualSearchConditions = (Dictionary <string, object>)Session["PrimaryKeyAndTimeStamp"];
        // タイムスタンプ列

        // 更新値(TimeStamp列は外す。
        parameterValue.InsertUpdateValues = new Dictionary <string, object>();
        //parameterValue.InsertUpdateValues.Add("ProductID", this.txtProductID.Text);
        parameterValue.InsertUpdateValues.Add("ProductName", this.txtProductName.Text);
        parameterValue.InsertUpdateValues.Add("SupplierID", this.txtSupplierID.Text);
        parameterValue.InsertUpdateValues.Add("CategoryID", this.txtCategoryID.Text);
        parameterValue.InsertUpdateValues.Add("QuantityPerUnit", this.txtQuantityPerUnit.Text);
        parameterValue.InsertUpdateValues.Add("UnitPrice", this.txtUnitPrice.Text);
        parameterValue.InsertUpdateValues.Add("UnitsInStock", this.txtUnitsInStock.Text);
        parameterValue.InsertUpdateValues.Add("UnitsOnOrder", this.txtUnitsOnOrder.Text);
        parameterValue.InsertUpdateValues.Add("ReorderLevel", this.txtReorderLevel.Text);
        parameterValue.InsertUpdateValues.Add("Discontinued", this.txtDiscontinued.Text);

        // B層を生成
        _3TierEngine b = new _3TierEngine();

        // データ取得処理を実行
        _3TierReturnValue returnValue =
            (_3TierReturnValue)b.DoBusinessLogic(
                (BaseParameterValue)parameterValue, DbEnum.IsolationLevelEnum.ReadCommitted);

        // 結果表示
        this.lblResult.Text = returnValue.Obj.ToString() + "件更新しました。";

        // 画面遷移しない。
        return(string.Empty);
    }
        /// <summary>ユーザ情報を取得する</summary>
        private void GetUserInfo()
        {
            // セッションステートレス対応
            if (this.HttpContext.Session == null)
            {
                // SessionがOFFの場合
            }
            else
            {
                // 取得を試みる。
                this.UserInfo = (MyUserInfo)UserInfoHandle.GetUserInformation();

                // nullチェック
                if (this.UserInfo == null)
                {
                    // nullの場合、仮の値を生成 / 設定する。
                    string userName = System.Threading.Thread.CurrentPrincipal.Identity.Name;

                    if (userName == null || userName == "")
                    {
                        // 未認証状態
                        this.UserInfo = new MyUserInfo("未認証", this.HttpContext.Request.UserHostAddress);
                    }
                    else
                    {
                        // 認証状態
                        this.UserInfo = new MyUserInfo(userName, this.HttpContext.Request.UserHostAddress);

                        // 必要に応じて認証チケットのユーザ名からユーザ情報を復元する。
                        // ★ 必要であれば、他の業務共通引継ぎ情報などをロードする。
                        // ・・・

                        // 復元したユーザ情報をセット
                        UserInfoHandle.SetUserInformation(this.UserInfo);
                    }
                }
            }
        }
Esempio n. 15
0
    /// <summary>
    /// ページロードのUOCメソッド(個別:初回ロード)
    /// </summary>
    /// <remarks>
    /// 実装必須
    /// </remarks>
    protected override void UOC_FormInit()
    {
        // フォーム初期化(初回ロード)時に実行する処理を実装する

        // TODO:

        // 詳細表示処理

        // 引数クラスを生成
        _3TierParameterValue parameterValue = new _3TierParameterValue(
            this.ContentPageFileNoEx, "FormInit", "SelectRecord",
            (string)Session["DAP"], (MyUserInfo)UserInfoHandle.GetUserInformation());

        // テーブル
        parameterValue.TableName = "Products";

        // 主キーとタイムスタンプ列
        // 主キー列
        parameterValue.AndEqualSearchConditions = (Dictionary <string, object>)Session["PrimaryKeyAndTimeStamp"];
        // タイムスタンプ列

        // B層を生成
        _3TierEngine b = new _3TierEngine();

        // データ取得処理を実行
        _3TierReturnValue returnValue =
            (_3TierReturnValue)b.DoBusinessLogic(
                (BaseParameterValue)parameterValue, DbEnum.IsolationLevelEnum.ReadCommitted);

        // 編集状態の初期化

        // 値
        this.txtProductID.Text       = returnValue.Dt.Rows[0]["ProductID"].ToString();
        this.txtProductName.Text     = returnValue.Dt.Rows[0]["ProductName"].ToString();
        this.txtSupplierID.Text      = returnValue.Dt.Rows[0]["SupplierID"].ToString();
        this.txtCategoryID.Text      = returnValue.Dt.Rows[0]["CategoryID"].ToString();
        this.txtQuantityPerUnit.Text = returnValue.Dt.Rows[0]["QuantityPerUnit"].ToString();
        this.txtUnitPrice.Text       = returnValue.Dt.Rows[0]["UnitPrice"].ToString();
        this.txtUnitsInStock.Text    = returnValue.Dt.Rows[0]["UnitsInStock"].ToString();
        this.txtUnitsOnOrder.Text    = returnValue.Dt.Rows[0]["UnitsOnOrder"].ToString();
        this.txtReorderLevel.Text    = returnValue.Dt.Rows[0]["ReorderLevel"].ToString();
        this.txtDiscontinued.Text    = returnValue.Dt.Rows[0]["Discontinued"].ToString();

        // 編集
        this.txtProductID.ReadOnly       = true;
        this.txtProductName.ReadOnly     = true;
        this.txtSupplierID.ReadOnly      = true;
        this.txtCategoryID.ReadOnly      = true;
        this.txtQuantityPerUnit.ReadOnly = true;
        this.txtUnitPrice.ReadOnly       = true;
        this.txtUnitsInStock.ReadOnly    = true;
        this.txtUnitsOnOrder.ReadOnly    = true;
        this.txtReorderLevel.ReadOnly    = true;
        this.txtDiscontinued.ReadOnly    = true;

        // 背景色
        this.txtProductID.BackColor       = System.Drawing.Color.LightGray;
        this.txtProductName.BackColor     = System.Drawing.Color.LightGray;
        this.txtSupplierID.BackColor      = System.Drawing.Color.LightGray;
        this.txtCategoryID.BackColor      = System.Drawing.Color.LightGray;
        this.txtQuantityPerUnit.BackColor = System.Drawing.Color.LightGray;
        this.txtUnitPrice.BackColor       = System.Drawing.Color.LightGray;
        this.txtUnitsInStock.BackColor    = System.Drawing.Color.LightGray;
        this.txtUnitsOnOrder.BackColor    = System.Drawing.Color.LightGray;
        this.txtReorderLevel.BackColor    = System.Drawing.Color.LightGray;
        this.txtDiscontinued.BackColor    = System.Drawing.Color.LightGray;
    }
Esempio n. 16
0
        /// <summary>
        /// 更新用户信息
        /// </summary>
        /// <param name="stuInfo">从教务处获取的,经过封装的用户信息</param>
        /// <param name="user">更新成功后的该学生信息</param>
        /// <returns></returns>
        public QssResult QssUpdateUserInfo(UserInfoHandle userInfo, out User user)
        {
            QssResult result = QssGetUserByAccount(userInfo.Account, out user);

            if (result == QssResult.Error)
            {
                // 获取到多个用户
                user = null;
                return(QssResult.Fail);
            }
            bool isFirst = false;

            if (result == QssResult.Fail)
            {
                // 第一次登录
                // 获取角色
                result = new RoleService().QssGetRoleByName(QssRoleType.User.ToString(), out Role role);
                if (result != QssResult.Success)
                {
                    user = null;
                    return(QssResult.Fail);
                }
                user = new User()
                {
                    Account = userInfo.Account,
                    Role    = role
                };
                isFirst = true;
            }

            // 更新信息
            if (userInfo.UserType == UserType.S.ToString())
            {
                // 学生
                user.Type    = UserType.S.ToString();
                user.Name    = userInfo.Name;
                user.Campus  = userInfo.Campus;
                user.College = userInfo.College;
                user.Grade   = Convert.ToInt32(userInfo.Grade);
                user.LoSch   = Convert.ToInt32(userInfo.LoSch);
                user.Class   = userInfo.NewClass; //永远获取新班级
                user.Major   = userInfo.NewMajor; //永远获取新专业
            }
            else
            {
                // 教师
                user.Type    = UserType.T.ToString();
                user.Name    = userInfo.Name;
                user.Campus  = userInfo.Campus;
                user.College = userInfo.College;
            }

            try
            {
                // 写入数据库
                if (isFirst)
                {
                    CurrentDal.Add(user);
                }
                else
                {
                    CurrentDal.Update(user);
                }
                DbSession.SaveChanges();
                return(QssResult.Success);
            }
            catch (Exception exception)
            {
                // 写入失败
                QssLogHelper.Log("写入用户信息失败", "在写入用户: " + user.Account + " 的用户信息时发生错误! 原因:" + exception.Message, QssLogType.Error, exception);
                return(QssResult.Fail);
            }
        }
Esempio n. 17
0
        public async Task <ActionResult> OAuth2AuthorizationCodeGrantClient(string code, string state)
        {
            try
            {
                string response = "";

                if (state == this.State) // CSRF(XSRF)対策のstateの検証は重要
                {
                    response = await OAuth2AndOIDCClient.GetAccessTokenByCodeAsync(
                        new Uri("https://localhost:44300/MultiPurposeAuthSite/token"),
                        OAuth2AndOIDCParams.ClientID, OAuth2AndOIDCParams.ClientSecret,
                        HttpUtility.HtmlEncode("http://localhost:58496/Home/OAuth2AuthorizationCodeGrantClient"), code);

                    // 汎用認証サイトはOIDCをサポートしたのでid_tokenを取得し、検証可能。
                    //Base64UrlTextEncoder base64UrlEncoder = new Base64UrlTextEncoder();
                    Dictionary <string, string> dic = JsonConvert.DeserializeObject <Dictionary <string, string> >(response);

                    // id_tokenの検証コード
                    if (dic.ContainsKey("id_token"))
                    {
                        string  sub   = "";
                        string  nonce = "";
                        JObject jobj  = null;

                        if (IdToken.Verify(dic["id_token"], dic["access_token"],
                                           code, state, out sub, out nonce, out jobj) && nonce == this.Nonce)
                        {
                            // ログインに成功

                            // /userinfoエンドポイントにアクセスする場合
                            response = await OAuth2AndOIDCClient.GetUserInfoAsync(
                                new Uri("https://localhost:44300/MultiPurposeAuthSite/userinfo"), dic["access_token"]);

                            // 認証情報を作成する。
                            List <Claim> claims = new List <Claim>();
                            claims.Add(new Claim(ClaimTypes.Name, sub));

                            // 認証情報を保存する。
                            ClaimsIdentity  userIdentity  = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                            ClaimsPrincipal userPrincipal = new ClaimsPrincipal(userIdentity);

                            // サイン アップする。
                            await AuthenticationHttpContextExtensions.SignInAsync(
                                this.HttpContext, CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal);

                            // 認証情報を保存する。
                            MyUserInfo ui = new MyUserInfo(sub, (new GetClientIpAddress()).GetAddress());
                            UserInfoHandle.SetUserInformation(ui);

                            return(this.Redirect(Url.Action("Index", "Home")));
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                }

                // ログインに失敗
                return(RedirectToAction("Login"));
            }
            finally
            {
                this.ClearExLoginsParams();
            }
        }
Esempio n. 18
0
 /// <summary>btnSetUserInfoのクリックイベント</summary>
 /// <param name="fxEventArgs">イベントハンドラの共通引数</param>
 /// <returns>URL</returns>
 protected string UOC_btnSetUserInfo_Click(FxEventArgs fxEventArgs)
 {
     // ユーザ情報を設定
     UserInfoHandle.SetUserInformation(new MyUserInfo(this.txtUserName.Text, Request.UserHostAddress));
     return(string.Empty);
 }
Esempio n. 19
0
 /// <summary>btnDelUserInfoのクリックイベント</summary>
 /// <param name="fxEventArgs">イベントハンドラの共通引数</param>
 /// <returns>URL</returns>
 protected string UOC_btnDelUserInfo_Click(FxEventArgs fxEventArgs)
 {
     // ユーザ情報を削除
     UserInfoHandle.DeleteUserInformation();
     return(string.Empty);
 }