Guest User

Untitled

a guest
Oct 25th, 2017
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1.  
  2. class LoginComponent{
  3. private _username:string;
  4. private _password:string;
  5. public login(username:string,password:string):boolean{
  6. if(this._username==username && this._password == password){
  7. return true;
  8. }
  9. else{
  10. return false;
  11. }
  12. }
  13. public setUserLogin(username:string,password:string){
  14. this._username=username;
  15. this._password=password;
  16. }
  17. }
  18. class SignupComponent{
  19. private _userlist:User[]=[];
  20. public printDetail(userid:number){
  21. if(this._userlist.length == 0){
  22. console.log("no user signed up\n");
  23. return;
  24. }
  25. var status=false;
  26. for(var i=0;i<this._userlist.length;i++){
  27. if(this._userlist[i].userId == userid){
  28. this._userlist[i].printDetail();
  29. status=true;
  30. }
  31. if(!status){
  32. console.log("no record found");
  33. }
  34. }
  35. }
  36. public addUser(user:User):boolean{
  37. try{
  38. this._userlist.push(user);
  39. return true;
  40. }
  41. catch{
  42. return false;
  43. }
  44. }
  45. }
  46. class User{
  47. public userId:number;
  48. public username:string;
  49. public password:string;
  50. public fullname:string;
  51. public age:number;
  52. public dateofbirth:Date;
  53. public phonenumber:number;
  54. public address:string;
  55. public emailId;
  56. public printDetail(){
  57. console.log(`User Id ${this.userId}\nFull Name ${this.fullname}\nDate OF birth ${this.dateofbirth}\nAge ${this.age}\nAddress ${this.address}\nphone Number ${this.phonenumber}\nEmail Id ${this.emailId}`);
  58. }
  59. }
  60. class Main{
  61. public entry(){
  62. var userObject=new User();
  63. userObject.userId=11;
  64. userObject.fullname="Akash Kumar";
  65. userObject.age=22;
  66. userObject.dateofbirth=new Date("1995-01-07");
  67. userObject.emailId="resakash1498@gmail.com";
  68. userObject.address="pune";
  69. userObject.phonenumber=9088192406;
  70. userObject.username="aksh123";
  71. userObject.password="aksh@123";
  72. var signupObject=new SignupComponent();
  73. if(signupObject.addUser(userObject)){
  74. console.log("user added successfully");
  75. }
  76. else{
  77. console.log("some error occured while adding");
  78. }
  79. var loginObject=new LoginComponent();
  80. loginObject.setUserLogin(userObject.username,userObject.password);
  81. if(loginObject.login(userObject.username,userObject.password)){
  82. console.log("login successful\nUser Details\n");
  83. signupObject.printDetail(userObject.userId);
  84. }
  85. else{
  86. console.log("Invalid parameter");
  87. }
  88. }
  89. }
  90. var mn=new Main();
  91. mn.entry();
Add Comment
Please, Sign In to add comment