public JsonResult GetAchievements(string token, string authHash) { /*---------------------------------Token Validation Begin-----------------------------------*/ #region Validate the Token //Get the current token from the database UnitOfWork work = new UnitOfWork(); external_token currentToken = work.SystemRepository.GetAuthorizationToken(token); //Invalid token if (currentToken == null) { return(Json(new MobileAppTokenErrorModel() { Success = false, Message = GetTokenValidationResultMessage(TokenValidationResult.FailureInvalid) })); } //Expired token if (DateTime.Now.CompareTo(currentToken.expiration_date) > 0) { return(Json(new MobileAppTokenErrorModel() { Success = false, Message = GetTokenValidationResultMessage(TokenValidationResult.FailureExpired) })); } //Build the string to be hashed string salt = currentToken.refresh_token; string paramString = "token=" + token; string stringToHash = salt + "?" + paramString; //Invalid hash if (!ValidateHash(stringToHash, authHash)) { return(Json(new MobileAppTokenErrorModel() { Success = false, Message = GetTokenValidationResultMessage(TokenValidationResult.FailureHash) })); } #endregion /*----------------------------------Token Validation End------------------------------------*/ //If the user has full Admin permissions, return all active achievements //If not, return all active achievements they are a caretaker of bool isFullAdmin = Roles.IsUserInRole(currentToken.user.username, JPPConstants.Roles.FullAdmin); List <achievement_template> assignableAchievements = work.AchievementRepository.GetAssignableAchievements(currentToken.user_id, isFullAdmin); //Create the list of achievements to return if (assignableAchievements != null && assignableAchievements.Count >= 0) { List <MobileAppAchievementModel> mobileAppAchievements = new List <MobileAppAchievementModel>(); foreach (achievement_template achievement in assignableAchievements) { MobileAppAchievementModel mobileAchievement = new MobileAppAchievementModel() { AchievementID = achievement.id, Icon = achievement.icon, Title = achievement.title }; mobileAppAchievements.Add(mobileAchievement); } return(Json(mobileAppAchievements)); } //The user cannot assign any achievements return(Json(new MobileAppTokenErrorModel() { Success = false, Message = GetLoginResultMessage(LoginValidationResult.FailureNoAchievements) })); }
public JsonResult GetAchievements(string token, string authHash) { /*---------------------------------Token Validation Begin-----------------------------------*/ #region Validate the Token //Get the current token from the database UnitOfWork work = new UnitOfWork(); external_token currentToken = work.SystemRepository.GetAuthorizationToken(token); //Invalid token if (currentToken == null) return Json(new MobileAppTokenErrorModel(){Success = false,Message = GetTokenValidationResultMessage(TokenValidationResult.FailureInvalid)}); //Expired token if (DateTime.Now.CompareTo(currentToken.expiration_date) > 0) return Json(new MobileAppTokenErrorModel() { Success = false, Message = GetTokenValidationResultMessage(TokenValidationResult.FailureExpired) }); //Build the string to be hashed string salt = currentToken.refresh_token; string paramString = "token=" + token; string stringToHash = salt + "?" + paramString; //Invalid hash if (!ValidateHash(stringToHash, authHash)) return Json(new MobileAppTokenErrorModel() { Success = false, Message = GetTokenValidationResultMessage(TokenValidationResult.FailureHash) }); #endregion /*----------------------------------Token Validation End------------------------------------*/ //If the user has full Admin permissions, return all active achievements //If not, return all active achievements they are a caretaker of bool isFullAdmin = Roles.IsUserInRole(currentToken.user.username, JPPConstants.Roles.FullAdmin); List<achievement_template> assignableAchievements = work.AchievementRepository.GetAssignableAchievements(currentToken.user_id, isFullAdmin); //Create the list of achievements to return if(assignableAchievements != null && assignableAchievements.Count >= 0) { List<MobileAppAchievementModel> mobileAppAchievements = new List<MobileAppAchievementModel>(); foreach (achievement_template achievement in assignableAchievements) { MobileAppAchievementModel mobileAchievement = new MobileAppAchievementModel() { AchievementID = achievement.id, Icon = achievement.icon, Title = achievement.title }; mobileAppAchievements.Add(mobileAchievement); } return Json(mobileAppAchievements); } //The user cannot assign any achievements return Json(new MobileAppTokenErrorModel() { Success = false, Message = GetLoginResultMessage(LoginValidationResult.FailureNoAchievements) }); }