Created
June 15, 2015 19:53
-
-
Save rushfrisby/e8e795ca24df5ba3e21a to your computer and use it in GitHub Desktop.
Intentionally bad code...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IUserService | |
{ | |
User GetUser(string userName); | |
} | |
public static class UserService : IUserService | |
{ | |
public User GetUser(string userName) | |
{ | |
using(var context = new SomeDbContext()) | |
{ | |
return context.Users.SqlQuery("SELECT * FROM [dbo].[User] WHERE [UserName]='" + userName + "'").First(); | |
} | |
} | |
} | |
public class UserController | |
{ | |
public static int CurrentUserId { get; set; } | |
private readonly IUserService _userService; | |
public UserController(IUserService userService) | |
{ | |
_userService = userService; | |
} | |
public ActionResult Login() | |
{ | |
return View(); | |
} | |
[HttpPost] | |
public ActionResult Login(string userName, string password) | |
{ | |
var user = _userService.GetUser(userName); | |
if(user == null) | |
{ | |
ViewBag.ErrorMessage = "User name does not exist"; | |
} | |
else | |
{ | |
if(user.Password == password) | |
{ | |
CurrentUserId = user.Id; | |
return RedirectToAction("Index"); | |
} | |
else | |
{ | |
ViewBag.ErrorMessage = "Incorrect password"; | |
} | |
} | |
return View(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment