Advertisement
EgonMilanVotrubec

Server/Controllers/PlayerController.cs

Nov 28th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2.  
  3. using Microsoft.AspNetCore.Authorization;
  4. using Microsoft.AspNetCore.Mvc;
  5.  
  6. using Server.Models;
  7.  
  8. namespace Server.Controllers
  9. {
  10.     [Route ( "[controller]" )]
  11.     public class PlayerController : Controller
  12.     {
  13.         private Player player;
  14.  
  15.  
  16.         public PlayerController ( )
  17.         {
  18.             // When the controller starts, let's create a dummy player.
  19.             player = new Player ( )
  20.             {
  21.                 ID = Guid.NewGuid ( ).ToString ( ),
  22.                 Name = "Milan Egon Votrubec",
  23.                 Alias = "Vot",
  24.                 Level = Player.PlayerLevel.Godlike
  25.             };
  26.         }
  27.  
  28.  
  29.  
  30.         [ AllowAnonymous]
  31.         [HttpPost ( "get" )]
  32.         public IActionResult Post ( [FromBody] UsernamePassword item )
  33.         {
  34.             // Let's check to see whether the caller has supplied the correct credentials.
  35.             if ( item?.Username != "user" || item?.Password != "pass" )
  36.                 return BadRequest ( "Bad username or password." );
  37.  
  38.             // At this point, we've successfully "Logged In". Let's return the player to the caller.
  39.             return Ok ( player );
  40.         }
  41.  
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement