public int ValidateToken() { int code = CODE_ILLEGAL_TOKEN; string token = GetToken(); //validate token if (!string.IsNullOrEmpty(token)) { //get management user by token ApiManagementUser mUser = mUserService.Get("", token); if (mUser == null) { code = CODE_ILLEGAL_TOKEN; } else { if (mUser.Expiry != null) { int res = DateTime.Compare(mUser.Expiry.Value, DateTime.Now); //it means token expiried. if (res < 0) { code = CODE_TOKEN_EXPIRED; } else { currentUser = mUser; code = CODE_NORMAL; } } } } return(code); }
public JObject Login(JObject parameter) { JObject response; string username = parameter["username"].ToString(); string password = parameter["password"].ToString(); ApiManagementUser mUser = managementUserService.Get("", "", username, password); if (mUser != null) { int aliveMinutes = Convert.ToInt16(ConfigurationManager.AppSettings["LoginAliveMinutes"]); mUser = managementUserService.GenerateToken(mUser.ID.ToString(), aliveMinutes); var data = ToJObject(mUser); response = CreateResponse(data); } else { response = CreateResponse(CODE_USER_PASSWORD_INCORRECT); } return(response); }
public ApiManagementUser ConvertDrToEntity(DataRow dr) { DateTime?expiry = null; if (dr["Expiry"] != DBNull.Value) { expiry = Convert.ToDateTime(dr["Expiry"]); } var record = new ApiManagementUser() { ID = Convert.ToInt64(dr["ID"]), Name = dr["Name"].ToString(), PasswordHash = dr["PasswordHash"].ToString(), Token = dr["Token"].ToString(), Expiry = expiry, //for editing use password = "", confirm = "" }; return(record); }