protected void TokenData(string APIKey, string Password) { if (string.IsNullOrEmpty(APIKey)) { result = falseresult("UnAuthorized..."); } else if (string.IsNullOrEmpty(Password)) { result = falseresult("Please provide Password..."); } else if (string.IsNullOrEmpty(IPAddress)) { result = falseresult("Please provide IP Address..."); } //if (!CheckPassEnscrypt(Password, ref Password)) //{ result = falseresult("UnAuthorized..."); } else { Department_ExMapDao map = new Department_ExMapDao(); try { OfficerToken _token = new OfficerToken(); string newToken = Guid.NewGuid().ToString(); string _Pass = Encryption.Encrypt(Password); var _obj = map.FindByKeygen(APIKey.Trim()); var obj = _obj.Where(o => o.Password == _Pass).FirstOrDefault(); if (obj != null) { GetAuthToken(_token, APIKey, newToken, IPAddress); //_token.Username = ""; //_token.Org_id = obj.ID.ToString(); _token.Org_name = obj.External_dept_Name; _token.Office_name = obj.External_dept_Name; SaveUtility.SaveTransactionLog(newToken, "GetToken", SaveUtility.TransStatus.Create, APIKey, IPAddress, "s"); //s: service result = Trueresult(_token); } else { result = falseresult("Invalid Token and Password..."); } } catch (Exception ex) { SaveUtility.logError(ex); result = falseresult(ex.Message.ToString()); } finally { map = null; } } HttpContext.Current.Response.ContentType = "application/json"; HttpContext.Current.Response.Write(JsonConvert.SerializeObject(result)); HttpContext.Current.Response.End(); }
protected void GetAuthToken(OfficerToken token, string key, string newKey, string ip) { AuthenticateTokenMapDao _authenMap = new AuthenticateTokenMapDao(); AuthenticateToken Obj = new AuthenticateToken(); //_authenMap.AddOrUpdate(Obj); var objToken = _authenMap.FindActiveByAPIKey(key).ToList(); foreach (var Items in objToken) { Items.Active = false; _authenMap.AddOrUpdate(Items); _authenMap.CommitChange(); } //if (objToken.Count() > 0) //{ // //disable token // foreach (var item in objToken) // { // if (item.Owner_ip == ip && Convert.ToDateTime(item.Process_date).AddMinutes(item.Process_time) > DateTime.Now) // { // token.Token_id = Encryption.Encrypt(item.Keygen); // } // else // { // item.Active = false; // _authenMap.AddOrUpdate(item); // _authenMap.CommitChange(); // } // } //} //if (string.IsNullOrEmpty(token.Token_id)) //{ var authen = new AuthenticateToken(key, newKey, ip); _authenMap.AddOrUpdate(authen); _authenMap.CommitChange(); token.Token_id = MyExtensions.ParamEncode(new { authen.ApiKey, Process_date = authen.Process_date.ToThaiFormateAndtime(), authen.Process_time, authen.Keygen }); //token = //} //_authenMap = null; }