public IActionResult Authorize([FromBody] User model) { AuthenticationReturn auth = AuthService.Authenticate(model); if (!auth.Status) { return(BadRequest(auth)); } return(Ok(auth)); }
public async Task <IActionResult> Post([FromBody] LoginAttributes loginAttributes) { //AuthService AuthenticationReturn auth = await AuthService.Authenticate(loginAttributes.Email, loginAttributes.Password); if (!auth.Status) { return(BadRequest(auth)); } return(Ok(new { token = auth.Token, id = auth.Id })); }
/// <summary> /// 登入遠端伺服器 /// </summary> /// <returns>返回值:true=登入程序已成功(等候onLogin事件通知), false=登入程序失敗</returns> public override bool Login() { if (this.IsLogin) { return true; } int iBufferSize = 1; byte[] bArray = new byte[64]; if (logger.IsInfoEnabled) logger.InfoFormat("[QuoteService.Login] Login signer service... service={0}({1}), userId={2}", this.RemoteIP, this.RemotePort, this.UserId); AuthenticationLogin authLogin = new AuthenticationLogin(this.UserId, this.Password, 0, 0); try { Socket cLogin = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); cLogin.Connect(new IPEndPoint(IPAddress.Parse(this.RemoteIP), this.RemotePort)); cLogin.Send(MitakePacket.ToBuffer(authLogin)); iBufferSize = cLogin.Receive(bArray); cLogin.Close(); } catch (Exception __errExcep) { logger.ErrorFormat("{0}\r\n{1}", __errExcep.Message, __errExcep.StackTrace); return false; } if (iBufferSize == 0) { return false; } else { AuthenticationReturn authReturn = null; authReturn = MitakePacket.ToStructure<AuthenticationReturn>(bArray, iBufferSize); __sUserID = this.UserId; __sSessionKey = authReturn.SessionKey; string sServiceIP = authReturn.RemoteIP; int iPort = authReturn.RemotePort; if (logger.IsInfoEnabled) logger.InfoFormat("[QuoteService.Login] Register service... service={0}({1}), userId={2}, sessionKey:{3}", sServiceIP, iPort, __sUserID, __sSessionKey); if (__cSocket == null) { __cSocket = new ZSocket(); __cSocket.ReceiveProc += SocketClient_onReceive; __cSocket.CloseProc += StockClient_onClose; } if (!RegisterServer(__cSocket, sServiceIP, iPort, 0x06)) { __cSocket.Close(); //關閉 Stream Socket __cSocket = null; return false; } if (__cSession == null) { __cSession = new ZSocket(); __cSession.ReceiveProc += SocketClient_onReceive; __cSession.CloseProc += StockClient_onClose; } if (!RegisterServer(__cSession, sServiceIP, iPort, 0x05)) { //如果註冊失敗 __cSocket.Close(); //關閉 Stream Socket(一定要 Stream 與 Session 兩條通道都同時建立完成, 才算是連線成功) __cSocket = null; __cSession.Close(); //關閉 Session Socket __cSession = null; return false; } lock (__cTimer) { __bTimeFlag = true; __cTimer.Start(); } StockDecoder.TimerProc += StockClient_onTimer; StockDecoder.StockProc += StockClient_onStock; McpDecoder.McpPacketProc += StockClient_onMcpPacket; MitakeSymbolManager.DataSource = this.DataSource; MitakeSymbolManager.ExchangeName = this.ExchangeName; StockDecoder.TimerProc += GetTradeDateFromLogin; //先取得最後交易日期之後再處理股票代號表之類的運作 this.SendSubscribe(); } return true; }