Advertisement
Guest User

Untitled

a guest
Mar 9th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 KB | None | 0 0
  1. namespace Forum.App.Controllers
  2. {
  3.     using Forum.App;
  4.     using Forum.App.Controllers.Contracts;
  5.     using Forum.App.UserInterface;
  6.     using Forum.App.UserInterface.Contracts;
  7.  
  8.     public class SignUpController : IController, IReadUserInfoController
  9.     {
  10.         private const string DETAILS_ERROR = "Invalid Username or Password!";
  11.         private const string USERNAME_TAKEN_ERROR = "Username already in use!";
  12.  
  13.         public string Username { get; private set; }
  14.         private string Password { get; set; }
  15.         private string ErrorMessage { get; set; }
  16.  
  17.         private enum Command
  18.         {
  19.             ReadUsername,ReadPassword,SignUp,Back
  20.         }
  21.  
  22.         public  enum SignUpStatus
  23.         {
  24.             Seccess,DetailsError,UsernameTakenError
  25.         }
  26.  
  27.         private void ResetSignUp()
  28.         {
  29.             this.ErrorMessage = string.Empty;
  30.             this.Username = string.Empty;
  31.             this.Password = string.Empty;
  32.         }
  33.  
  34.         public MenuState ExecuteCommand(int index)
  35.         {
  36.             switch ((Command)index)
  37.             {
  38.                 case Command.ReadUsername:
  39.                     this.ReadUsername();
  40.                     return MenuState.Signup;
  41.                 case Command.ReadPassword:
  42.                     this.ReadPassword();
  43.                     return MenuState.Signup;
  44.                 case Command.SignUp:
  45.                     SignUpStatus signUp = UserService.TrySignUpUser(this.Username, this.Password);
  46.                     switch (signUp)
  47.                     {
  48.                         case SignUpStatus.Seccess:
  49.                             return MenuState.SuccessfulLogIn;
  50.                         case SignUpStatus.DetailsError:
  51.                             this.ErrorMessage = DETAILS_ERROR;
  52.                             return MenuState.Error;
  53.                         case SignUpStatus.UsernameTakenError:
  54.                             this.ErrorMessage = USERNAME_TAKEN_ERROR;
  55.                             return MenuState.Error;
  56.                            
  57.                     }
  58.                     break;
  59.  
  60.                    // return MenuState.Error;
  61.                 case Command.Back:
  62.                     this.ResetSignUp();
  63.                     return MenuState.Back;
  64.              
  65.             }
  66.             throw new System.InvalidOperationException();
  67.         }
  68.  
  69.         public IView GetView(string userName)
  70.         {
  71.             return new SignUpView(this.ErrorMessage);
  72.         }
  73.  
  74.         public void ReadPassword()
  75.         {
  76.             this.Password = ForumViewEngine.ReadRow();
  77.             ForumViewEngine.HideCursor();
  78.         }
  79.  
  80.         public void ReadUsername()
  81.         {
  82.             this.Username = ForumViewEngine.ReadRow();
  83.             ForumViewEngine.HideCursor();
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement