public async Task <AccountsJwtTokenModel> Token(IssueTokenModel model) { var user = await accService.AutheticateUser(model.Username, model.Password); var handler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(settings.JwtKey); var expires = DateTime.Now.AddSeconds(settings.JwtExpires); var descriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.Id.ToString()) }), Expires = expires, SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha512Signature) }; var token = handler.CreateToken(descriptor); return(new AccountsJwtTokenModel { Token = handler.WriteToken(token), Expires = expires }); }
public ActionResult Index(IssueTokenModel model) { var isValid = true; // if something in the verification doesn't work if (!ModelState.IsValid) { // is valid is false isValid = false; } // IF the token type is subscription run this check! if (model.TokenType == Models.IssueToken.TokenType.Subscription) { int subscriptionMonths; // If not able to parse? then if (!int.TryParse(model.TokenValue, out subscriptionMonths)) { // try to parse the int, and if it's not an int then error message ModelState.AddModelError("Subscription Months", "Subscription months must be a number."); isValid = false; } if (subscriptionMonths < 1 || subscriptionMonths > 24) { // if the int is out of range then display an error!! ModelState.AddModelError("Subscription Months", "Subscriptions may only be issued for between 1 and 24 months."); isValid = false; } } // if all the checks pass then proceed and it's valid if (isValid) { // go to the verifyIssueToken partial view & display the model information return(View("VerifyIssueToken", model)); } return(View(model)); }
public ActionResult HandleVerify(IssueTokenModel model) { // Write all your code for sending to the database here; we know we have a valid token and the // user has confirmed they want to issue it, so it's time to do that now. // send data to the data base (see the create function below??) if (ModelState.IsValid) { // We will go from a model to an entity because we're saving to the database. // We know that the model contains values that are safe to store because of the // ModelState.IsValid check above, so we know we won't write anything that'll screw // up the database. var token = new TokenEntity { TokenCode = Guid.NewGuid(), // Our new identifier. The user doesn't get to pick one, so we do that here. TokenType = ToEntityTokenType(model.TokenType), TokenContent = model.TokenContent, IssuingReason = model.Reason, IssuingComments = model.Comments, EmailAddress = model.EmailAddress, TokenValue = model.TokenValue, Status = true // All issued tokens are by default active - the user can't issue a deactivated token. }; // Now we're adding the token to the database... tokens.IssuedTokens.Add(token); // ... and saving it. tokens.SaveChanges(); //return View(); // Assuming we got here, the save worked fine. Go ahead and return control to the page; // our Javascript will pop up the alert saying that it's successful. return(new HttpStatusCodeResult(HttpStatusCode.OK)); } // Stays on the page if there is an error... (set to display system error message) return(View(model)); }
/// <summary> /// Get the tokens to display in the issueToken Page? ( link this to the /// the TokenCategory??? - How to GET data from one controller to another?) /// How to GET data from one Table in DB /// </summary> // GET: IssueTokenModels public ActionResult Index() { // Filling the Token Content attributes to display on the page var model = new IssueTokenModel { // FILL THE SET CONTENT VALUES! GameTokenContent = new SelectListItem[] { new SelectListItem() { Value = "Battle Of The Worlds", Text = "Battle Of The Worlds" }, new SelectListItem() { Value = "Builder Blocks 2", Text = "Builder Blocks 2" }, new SelectListItem() { Value = "Builder Blocks 3", Text = "Builder Blocks 3" }, new SelectListItem() { Value = "Diver Craze", Text = "Diver Craze" }, new SelectListItem() { Value = "Diver Craze 2", Text = "Diver Craze 2" }, new SelectListItem() { Value = "Race To Mars", Text = "Race To Mars" }, new SelectListItem() { Value = "Rock 'Em Sock 'Em", Text = "Rock 'Em Sock 'Em" } }, SubscriptionTokenContent = new SelectListItem[] { new SelectListItem() { Value = "EducationOnline", Text = "EducationOnline" }, //Values WERE subscription1 & Subscription2 new SelectListItem() { Value = "GamersPlus", Text = "GamersPlus" } // keep these values the same, feed them directly from the db }, // good practice to set to empty //FILL THE TOKEN VALUES (SUBSCRIPTION IS A RANGE SO NA) GameTokenValue = new SelectListItem[] { new SelectListItem() { Value = "Standard Ed.", Text = "Standard Edition" }, new SelectListItem() { Value = "Speical Ed.", Text = "Special Edition" }, new SelectListItem() { Value = "DLC-100 game Currency", Text = "DLC-100 game Currency" }, new SelectListItem() { Value = "DLC-50 game Currency", Text = "DLC-50 game Currency" }, new SelectListItem() { Value = "DLC-Character", Text = "DLC-Character" }, new SelectListItem() { Value = "DLC-Bonus Lvl", Text = "DLC-Bonus Level" } }, //Set contents for the Reason Drop down for issuing a token ReasonChoices = new SelectListItem[] { new SelectListItem() { Value = "Make Good", Text = "Make Good" }, new SelectListItem() { Value = "Troubleshooting Issues - System", Text = "Troubleshooting Issues - System" }, new SelectListItem() { Value = "Technical Issues - System", Text = "Technical Issues - System" }, new SelectListItem() { Value = "Promotion Not Received", Text = "Promotional Token Not Received" }, new SelectListItem() { Value = "Damaged", Text = "Damaged Code" }, new SelectListItem() { Value = "Missing From Bundle", Text = "Missing Item From Bundle" }, new SelectListItem() { Value = "Inactive Status", Text = "Inactive Status" }, new SelectListItem() { Value = "Invalid Code", Text = "Invalid Code" }, new SelectListItem() { Value = "Incorrect Token Issued", Text = "Incorrect Token Type Issued" }, }, // good practice to set to empty TokenContent = string.Empty //TokenValue = string.Empty }; return(View(model)); }