public ResultObject Login(string loginname, string password) { try { User user = _context.Users .AsNoTracking() .Where(a => a.LoginName == loginname && a.Password == password) .Single(); String tockenid = Tocken.GetTockenID(); _cache.Set(tockenid, user, new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(20))); return(new ResultObject { state = ResultState.Success, result = tockenid }); } catch (InvalidOperationException ex) { return(new ResultObject { state = ResultState.Exception, ExceptionString = "未找到匹配的数据" }); } }
// // GET: /takemoney/ // POST api/logout public HttpResponseMessage Post(Tocken tocken) { if (!this.ModelState.IsValid) { //tutaj wywala ogolny blad gdy otrzymal zle dane throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest)); } MoneyResponse reply = new MoneyResponse { ok = 0, currentMoney = 0.0 }; //pobierz saldo kolesia z takim tocken.tocken wpisz w money //bledy ok masz opisane w MoneyResponse //todo //sciaga stan konta double stanKonta = -1; //pobiera stan konta z bazy danych na podstawie tokena if (Zapytania.pobierzStanKonta(tocken.tocken, ref stanKonta) == true) { reply.ok = 0; reply.currentMoney = stanKonta; } else { reply.ok = 1; } HttpResponseMessage response = this.Request.CreateResponse(HttpStatusCode.Created, reply); return(response); }
public LoginInfo GetToken(AcceptLoginInfo usr) { var model = ValidationHelper.Login(usr); if (model.Status != 1) { return(model); } using (DBController db = new DBController()) { Panda_UserInfo dbItem = db.Panda_UserInfo.FirstOrDefault(u => u.UserName == usr.UserName && u.UserPwd == usr.Md5); if (dbItem != null) { model.Message = string.Empty;; model.ErrorCode = string.Empty; model.Status = 1; model.TokenID = Guid.NewGuid().ToString(); var delItem = db.Tocken.FirstOrDefault(o => o.UserName == usr.UserName); if (delItem != null) { db.Tocken.Remove(delItem); } Tocken tk = new Tocken(); tk.TockenID = model.TokenID; tk.UpdateTime = DateTime.Now; tk.UserName = usr.UserName; db.Tocken.Add(tk); db.SaveChanges(); model.Message = "登录成功。"; model.ErrorCode = ""; model.Status = 1; model.UserID = dbItem.ID.ToString(); } else { model.Message = "用户名或密码错误。"; model.ErrorCode = "103"; model.Status = 0; model.TokenID = ""; model.UserID = ""; } } return(model); }
public void GetToken111() { using (DBController db = new DBController()) { Tocken tk = new Tocken(); tk.TockenID = Guid.NewGuid().ToString(); tk.UpdateTime = DateTime.Now; tk.UserName = "******"; db.Tocken.Add(tk); db.SaveChanges(); int a = 1; } }
// // GET: /currentTicket/ public HttpResponseMessage Post(Tocken tocken) { if (!this.ModelState.IsValid) { //tutaj wywala ogolny blad gdy otrzymal zle dane throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest)); } //currentTicketAnswer reply = new currentTicketAnswer { ok = 0, whatTicket = "nazwa231",timeTicket = "czas"}; //ok = 0 ma bilet what ticket ma nazwe tego biletu a time ticket to czas biletu w stringu i w danym formacie 2015:05:22:22:59:00 ( rok,mieisac,dzien,godz,min,sec) czyli do kiedy jest bilet //ok = 1 to brak biletu i brak aktualnego biletu List <Ticket> lista_biletow = new List <Ticket>(); if (Zapytania.czyAktualnyBilet(tocken.tocken, ref lista_biletow) == true) { //reply.ok = 0; } else { //reply.ok = 1; //blad lista_biletow = null; } //string nazwa = ""; //string DO = ""; //if (Zapytania.czyAktualnyBilet(tocken.tocken, ref nazwa, ref DO) == true) //{ // reply.whatTicket = nazwa; // reply.timeTicket = DO; // reply.ok = 0; //} //else //{ // reply.ok = 1; //blad // //reply.whatTicket = "zly"; // reply.timeTicket = (nazwa == "") ? "pusty_string" : nazwa; // reply.whatTicket = (DO == "") ? "token: "+tocken.tocken : DO; //} HttpResponseMessage response = this.Request.CreateResponse(HttpStatusCode.Created, lista_biletow); return(response); }
// POST api/logout public HttpResponseMessage Post(Tocken tocken) { if (!this.ModelState.IsValid) { //tutaj wywala ogolny blad gdy otrzymal zle dane throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest)); } if (Zapytania.usun_token2(tocken.tocken) == true) { tocken.tocken = "ok"; } else { tocken.tocken = "bad"; } HttpResponseMessage response = this.Request.CreateResponse(HttpStatusCode.Created, tocken); return(response); }
public object Any(Tocken request) { var tfa = new TwoFactorAuthenticator(); return(tfa.GetCurrentPIN("ba6896eb43f547be8b476649a5ff43f3")); }