public HttpResponseMessage PostLogin(ViewLogin viewLogin) { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new { result = false, message = "登入失敗!" })); } Customer customer = ValidateUser(viewLogin.Email, viewLogin.Password);//檢查會員登入密碼 if (customer == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, new { result = false, message = "帳號或密碼錯誤!" })); } JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string jwtToken = jwtAuthUtil.GenerateToken(customer.Id, "0"); return(Request.CreateResponse(HttpStatusCode.OK, new { result = true, message = "登入成功", id = customer.Id, token = jwtToken })); }
// GET api/values public object GetToken() { JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string jwtToken = jwtAuthUtil.GenerateToken(); return(new { token = jwtToken }); }
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 = "信箱或是密碼輸入格式有誤" })); }
public HttpResponseMessage Post(ViewLogin viewLogin) { if (ModelState.IsValid) { if (viewLogin.Permission == "04") { Student student = ValidateStudentUser(viewLogin.Account, viewLogin.Password); if (student != null) { JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string jwtToken = jwtAuthUtil.GenerateToken(student.Id, student.Permission); return(Request.CreateResponse(HttpStatusCode.OK, new { code = 1, token = jwtToken, message = "登入成功" })); } return(Request.CreateResponse(HttpStatusCode.OK, new { code = 5567, message = "帳密錯誤或身分不符" })); } Teacher teacher = ValidateTeacherUser(viewLogin.Account, viewLogin.Password, viewLogin.Permission); if (teacher != null) { JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string jwtToken = jwtAuthUtil.GenerateToken(teacher.Id, teacher.Permission.ToString()); return(Request.CreateResponse(HttpStatusCode.OK, new { code = 1, token = jwtToken, message = "登入成功" })); } return(Request.CreateResponse(HttpStatusCode.OK, new { code = 5567, message = "帳密錯誤或身分不符" })); } return(Request.CreateResponse(HttpStatusCode.OK, new { code = 5567, message = "登入失敗" })); }
public WebAPIReponse SignIn([FromBody] UserAccountRequest userAccount) { try { AccountInfo mtsAccountInfo = new AccountInfo(); mtsAccountInfo.UserID = userAccount.LoginAccount; PassWordHelper passWordHelper = new PassWordHelper(userAccount.LoginPassword); mtsAccountInfo.PassWord = passWordHelper.CrtPassWord(); var userInfo = _usersService.Login(mtsAccountInfo); if (userInfo != null) { // 校验密码,生成 Token JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); JwtAuthObject jwtAuthInfo = new JwtAuthObject { UserName = userInfo.UserID, }; switch (userAccount.LoginPlatform) { case SoftPlatform.mtsToolCaliburn: jwtAuthInfo.ExpiryDateTime = DateTime.Now.AddHours(12).ToString(); break; case SoftPlatform.mtsToolLoggerCenter: jwtAuthInfo.ExpiryDateTime = DateTime.Now.AddHours(4).ToString(); break; case SoftPlatform.mtsToolsSchedule: jwtAuthInfo.ExpiryDateTime = DateTime.Now.AddMinutes(15).ToString(); break; case SoftPlatform.mtsToolsStudio: jwtAuthInfo.ExpiryDateTime = DateTime.Now.AddHours(4).ToString(); break; default: jwtAuthInfo.ExpiryDateTime = DateTime.Now.AddMinutes(5).ToString(); break; } string jwtToken = jwtAuthUtil.GenerateToken(jwtAuthInfo); return(new WebAPIReponse(HttpStatusCode.OK, "OK", jwtToken)); } return(new WebAPIReponse(HttpStatusCode.NonAuthoritativeInformation, "Access Denied")); } catch (Exception exception) { return(new WebAPIReponse(HttpStatusCode.PreconditionFailed, "Precondition Failed", exception.ToString())); } }
public HttpResponseMessage PostLogin(ViewLogin viewLogin) { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new { result = false, message = "登入失敗!" })); } Brand brand = ValidateUser(viewLogin.Email, viewLogin.Password);//檢查會員登入密碼 if (brand == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, new { result = false, message = "帳號或密碼錯誤!" })); } else if (brand.Verification != Verification.是) { return(Request.CreateResponse(HttpStatusCode.NotFound, new { result = false, message = "帳號尚未驗證開通!" })); } JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string jwtToken = jwtAuthUtil.GenerateToken(brand.Id, "1"); return(Request.CreateResponse(HttpStatusCode.OK, new { result = true, message = "登入成功", id = brand.Id, token = jwtToken })); }
// POST: api/Login public Object Post(LoginRequest loginRequest) { if (loginRequest.account == "jim" && loginRequest.password == "12345") { JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string jwtToken = jwtAuthUtil.GenerateToken(); return(new { status = true, token = jwtToken }); } else { return(new { status = false, token = "Account Or Password Error" }); } }
public async Task <HttpResponseMessage> Login([FromBody] AccountInfo info) { using (UserDbEntities entities = new UserDbEntities()) { // Search user by ID, and then vaerify the password. var entity = await entities.Users.FirstOrDefaultAsync(e => e.UserID == info.UserID); if (entity != null) { BCryptUtil bCrypt = new BCryptUtil(); bool result = bCrypt.Verify(info.Password, entity.PasswordHash); if (result) { JwtAuthUtil jwt = new JwtAuthUtil(entity.GUID.ToString()); // token for portal login string accessToken = jwt.GenerateToken(); // return necessary information to the front end return(Request.CreateResponse(HttpStatusCode.OK, new { guid = entity.GUID.ToString().ToUpper(), lifeQual = entity.SalesLifeQual.ToUpper(), propQual = entity.SalesPropQual.ToUpper(), access_token = accessToken })); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Wrong password!!")); } } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No such user!")); } } }
public HttpResponseMessage MemberLogin(ViewLogin viewLogin) { Member member = ValidateUser(viewLogin.Email, viewLogin.Password); if (member != null) { JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string jwtToken = jwtAuthUtil.GenerateToken(member.id, member.Email); return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "登入成功", token = jwtToken, member.points, member.Permission, member.id, member.Email })); //return Request.CreateResponse(HttpStatusCode.OK, // new { success = true, message = "登入成功" }); } return(Request.CreateResponse(HttpStatusCode.NotFound, new { success = false, message = "登入失敗" })); }
public HttpResponseMessage GenerateToken([FromBody] TokenInfo info) { if (info == null || String.IsNullOrEmpty(info.UserGUID) || String.IsNullOrEmpty(info.Insurer)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "All Fields are required.")); } try { // Send UserGUID and insurerCode to generate the token JwtAuthUtil jwt = new JwtAuthUtil(info.UserGUID, info.Insurer); string access_token = jwt.GenerateToken(); return(Request.CreateResponse(HttpStatusCode.OK, new { access_token = access_token })); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
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 = "信箱或是密碼輸入格式有誤" })); }