コード例 #1
0
ファイル: MembersController.cs プロジェクト: ga503306/pet
        public IHttpActionResult Login(CompanyLoginModel companyLoginModel)//companglinemodel與member相同
        {
            if (ModelState.IsValid)
            {
                Member member = GetUser(companyLoginModel.email);
                if (member == null)
                {
                    return(Ok(new
                    {
                        result = "登入失敗:查無此信箱,請註冊"
                    }));
                }

                bool Validated = ValidateUser(companyLoginModel.pwd, member.pwd, member.pwdsalt);
                if (Validated) //驗證成功 帳密一致true / 驗證失敗false
                {
                    string      userData    = JsonConvert.SerializeObject(member);
                    JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
                    string      jwtToken    = jwtAuthUtil.GenerateToken(companyLoginModel.email, member.memberseq);

                    return(Ok(new
                    {
                        result = "登入成功",
                        token = jwtToken,
                        //name = FormsAuthentication.FormsCookieName,
                        //value = encryptedTicket
                    }));
                }
                else
                {
                    //判斷 帳號是否被封鎖
                    if (member.del_flag == "Y")
                    {
                        return(Ok(new
                        {
                            result = "登入失敗:此信箱已被平台封鎖"
                        }));
                    }
                    else
                    {
                        return(Ok(new
                        {
                            result = "登入失敗:信箱或密碼錯誤"
                        }));
                    }
                }
            }
            return(Ok(new
            {
                result = "信箱或是密碼輸入格式有誤"
            }));
        }
コード例 #2
0
ファイル: CompaniesController.cs プロジェクト: ga503306/pet
        public IHttpActionResult Login(CompanyLoginModel companyLoginModel)
        {
            if (ModelState.IsValid)
            {
                Company company = GetUser(companyLoginModel.email);
                if (company == null)
                {
                    return(Ok(new
                    {
                        result = "登入失敗:查無此信箱,請註冊"
                    }));
                }

                bool Validated = ValidateUser(companyLoginModel.pwd, company.pwd, company.pwdsalt);
                if (Validated) //驗證成功 帳密一致true / 驗證失敗false
                {
                    //string userData = JsonConvert.SerializeObject(company);
                    ////Utility.SetAuthenTicket(userData, companyLoginModel.email);
                    ////宣告一個驗證票
                    //FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, companyLoginModel.email, DateTime.Now, DateTime.Now.AddHours(3), false, userData);
                    ////加密驗證票
                    //string encryptedTicket = FormsAuthentication.Encrypt(ticket);
                    ////建立Cookie
                    //HttpCookie authenticationcookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                    ////將Cookie寫入回應
                    //HttpContext.Current.Response.Cookies.Add(authenticationcookie);

                    string      userData    = JsonConvert.SerializeObject(company);
                    JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
                    string      jwtToken    = jwtAuthUtil.GenerateToken(companyLoginModel.email, company.companyseq);

                    return(Ok(new
                    {
                        result = "登入成功",
                        token = jwtToken,
                        //name = FormsAuthentication.FormsCookieName,
                        //value = encryptedTicket
                    }));
                }
                else
                {
                    //判斷 帳號是否被封鎖
                    if (company.del_flag == "Y")
                    {
                        return(Ok(new
                        {
                            result = "登入失敗:此信箱已被平台封鎖"
                        }));
                    }
                    else
                    {
                        return(Ok(new
                        {
                            result = "登入失敗:信箱或密碼錯誤"
                        }));
                    }
                }
            }
            return(Ok(new
            {
                result = "信箱或是密碼輸入格式有誤"
            }));
        }