Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.64 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileReader;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.io.PrintWriter;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. import java.util.Scanner;
  11. import java.util.regex.Pattern;
  12.  
  13. import com.opencsv.CSVReader;
  14.  
  15.  
  16. public class MarketPlace {
  17.  
  18. private boolean loggedin = false;
  19. private Scanner userGetter;
  20. private Scanner passGetter;
  21. private Scanner emailGetter;
  22. private Scanner typeGetter;
  23. private Scanner updater;
  24. private String currentUsername = "";
  25.  
  26. //Keeps a list of Sellers and Buyers that can be accessed by a Market Place Admin.
  27. private ArrayList<Buyer> buyers = new ArrayList<>();
  28. private ArrayList<Seller> sellers = new ArrayList<>();
  29. //MAIN METHOD
  30. public static void main(String[] args) throws FileNotFoundException {
  31. MarketPlace testMarketPlace = new MarketPlace();
  32.  
  33. }
  34. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  35.  
  36. public MarketPlace() throws FileNotFoundException {
  37.  
  38. Scanner reader1 = new Scanner(System.in);
  39. System.out.println("Welcome!\n");
  40. System.out.println(helpMenu());
  41.  
  42. while (true) {
  43. String input = reader1.next();
  44.  
  45. if (input.equals("login")) {
  46. System.out.println("Enter your username");
  47. String userSelect = reader1.next();
  48. System.out.println("Enter your password");
  49. String passSelect = reader1.next();
  50.  
  51. userSelect = userSelect.toLowerCase();
  52.  
  53. // this is where I validate the username and password
  54. if (login(userSelect, passSelect).equals("Buyer")) {
  55. Buyer buyer = new Buyer();
  56. buyers.add(buyer); //Add buyer to master buyer list
  57.  
  58. //System.out.println("\n" + helpMenu());
  59. } else if(login(userSelect, passSelect).equals("MarketPlaceAdmin")) {
  60. MarketPlaceAdmin admin = new MarketPlaceAdmin();
  61. } else if (login(userSelect, passSelect).equals("Seller")) {
  62. Seller seller = new Seller();
  63. sellers.add(seller); //add seller to master seller list
  64. }
  65.  
  66.  
  67. else {
  68. System.out.println("incorrect combination, please try again add something here");
  69. }
  70. }else if (input.equals("logout")) {
  71. loggedin = false;
  72. System.out.println("logged out");
  73. System.out.println("\n" + helpMenu());
  74. } else if (input.equals("search")) {
  75. System.out.println("searching...");
  76. System.out.println("\n" + helpMenu());
  77. } else if (input.equals("help")) {
  78. System.out.println("\n" + helpMenu());
  79. } else if(input.equals("register")){
  80. register();
  81. }else {
  82. System.out.println("Sorry, I cannot recognize your command, please try again");
  83. System.out.println("\n" + helpMenu());
  84. }
  85. }
  86.  
  87. }
  88.  
  89. // we may need to move this method to each individual class to customize it
  90. // for the type of user
  91. private String helpMenu() {
  92. String help = "Enter a command below (without the quotes) to continue.\n\n";
  93.  
  94. if (loggedin) {
  95. help += "\"logout\" to logout\n";
  96. } else {
  97. help += "\"register\" to register\n";
  98. help += "\"login\" to login\n";
  99. }
  100. help += "\"search\" to search for items\n";
  101. help += "\"help\" anytime to see this message again\n";
  102. return help;
  103. }
  104.  
  105. private void register() throws FileNotFoundException {
  106.  
  107. String newUsername = uniqueUsername();
  108.  
  109. String newPassword = newPassword();
  110.  
  111. String newEmail = newEmail();
  112.  
  113. String accountType = accountType();
  114.  
  115. int newID = makeID();
  116.  
  117. try {
  118. FileWriter pw = new FileWriter("bin/creds.csv",true);
  119. StringBuilder sb = new StringBuilder();
  120.  
  121. sb.append(Integer.toString(newID));
  122. sb.append(",");
  123. sb.append(newUsername);
  124. sb.append(",");
  125. sb.append(newPassword);
  126. sb.append(",");
  127. sb.append(newEmail);
  128. sb.append(",");
  129. sb.append(accountType);
  130. sb.append("\n");
  131.  
  132. pw.write(sb.toString());
  133.  
  134.  
  135. pw.close();
  136.  
  137. } catch (IOException e) {
  138. e.printStackTrace();
  139. }
  140.  
  141. System.out.println("\nNew Account has been created!\n");
  142.  
  143. System.out.print(helpMenu());
  144. }
  145.  
  146. private int makeID() throws FileNotFoundException {
  147. BufferedReader reader = new BufferedReader(new FileReader("bin/creds.csv"));
  148. String thisLine;
  149. int max = 0;
  150. try {
  151. thisLine = reader.readLine();
  152. while ((thisLine = reader.readLine()) != null) {
  153. thisLine = thisLine.trim();
  154. String[] items = thisLine.split(",");
  155. String id = items[0];
  156. int idNum = Integer.parseInt(id);
  157. if (idNum > max) {
  158. max = idNum;
  159. }
  160. }
  161. } catch (IOException e) {
  162. System.out.print("\nUser does not exist\n");
  163. e.printStackTrace();
  164. } finally {
  165. try {
  166. reader.close();
  167. } catch (IOException e) {
  168. /* ignore */ }
  169. }
  170.  
  171. return (max+1);
  172. }
  173.  
  174. private String uniqueUsername() throws FileNotFoundException{
  175. boolean unique;
  176.  
  177. String newUsername;
  178.  
  179. userGetter = new Scanner(System.in);
  180.  
  181. do{
  182.  
  183. System.out.print("Please enter a Username: ");
  184. unique = true;
  185.  
  186. newUsername = userGetter.next();
  187. newUsername = newUsername.toLowerCase();
  188.  
  189. BufferedReader reader = new BufferedReader(
  190. new FileReader("bin/creds.csv"));
  191. String thisLine;
  192. try {
  193. thisLine = reader.readLine();
  194. while ((thisLine = reader.readLine()) != null) {
  195. thisLine = thisLine.trim();
  196. String[] items = thisLine.split(",");
  197. String user = items[1];
  198. user=user.toLowerCase();
  199.  
  200. if(newUsername.equals(user)){
  201. unique=false;
  202. System.out.println("Not a unique Username. Please try again");
  203. }
  204. }
  205. }catch (IOException e) {
  206. e.printStackTrace();
  207. } finally {
  208. try {
  209. reader.close();
  210. } catch (IOException e) {
  211. /* ignore */ }
  212. }
  213.  
  214. try {
  215. reader.close();
  216. } catch (IOException e) {
  217. e.printStackTrace();
  218. }
  219. }
  220. while(!unique);
  221.  
  222. return newUsername;
  223. }
  224.  
  225. private String newPassword(){
  226. String newPassword;
  227. String confimationPassword;
  228.  
  229. passGetter = new Scanner(System.in);
  230.  
  231. while(true){
  232. System.out.print("\nPlease enter a password: ");
  233. newPassword = passGetter.next();
  234.  
  235. System.out.print("Please enter your password again: ");
  236. confimationPassword = passGetter.next();
  237.  
  238. if (newPassword.equals(confimationPassword)) break;
  239. else System.out.print("Passwords did not match, try again!\n");
  240. }
  241.  
  242. return newPassword;
  243. }
  244.  
  245. private String accountType(){
  246. String type;
  247.  
  248. typeGetter = new Scanner(System.in);
  249.  
  250. while(true){
  251. System.out.print("\nWill you be a Buyer or Seller?: ");
  252. type = typeGetter.next();
  253.  
  254. type = toTitleCase(type);
  255.  
  256. if(type.equals("Buyer") || type.equals("Seller")) break;
  257. else System.out.print("Not a valid input, try again!");
  258. }
  259.  
  260. return type;
  261. }
  262.  
  263. private static String toTitleCase(String input) {
  264. StringBuilder titleCase = new StringBuilder();
  265. boolean nextTitleCase = true;
  266.  
  267. for (char c : input.toCharArray()) {
  268. if (Character.isSpaceChar(c)) {
  269. nextTitleCase = true;
  270. } else if (nextTitleCase) {
  271. c = Character.toTitleCase(c);
  272. nextTitleCase = false;
  273. }
  274.  
  275. titleCase.append(c);
  276. }
  277.  
  278. return titleCase.toString();
  279. }
  280.  
  281. private String newEmail(){
  282. String newEmail;
  283. String confimationEmail;
  284.  
  285. emailGetter = new Scanner(System.in);
  286.  
  287. //RFC822 compliant regex for email
  288. Pattern ptr = Pattern.compile("(?:(?:\\r\\n)?[ \\t])*(?:(?:(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[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[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*\\>(?:(?:\\r\\n)?[ \\t])*))*)?;\\s*)");
  289.  
  290. while(true){
  291. System.out.print("\nPlease enter an email: ");
  292. newEmail = emailGetter.next();
  293.  
  294. System.out.print("Please enter your email again: ");
  295. confimationEmail = emailGetter.next();
  296.  
  297. if (newEmail.equals(confimationEmail) && ptr.matcher(newEmail).matches()) break;
  298. else if (!(ptr.matcher(newEmail).matches())) System.out.print("Not a legal email!\n");
  299. else System.out.print("Emails did not match, try again!\n");
  300. }
  301.  
  302. return newEmail;
  303. }
  304.  
  305.  
  306.  
  307. private String viewStock() {
  308. return null;
  309.  
  310. }
  311.  
  312. private void updateCreds() {
  313. String userResponse;
  314.  
  315. String username;
  316.  
  317. boolean pass = false;
  318. boolean email = true;
  319. CSVReader reader = null;
  320. try {
  321. reader = new CSVReader(new FileReader("bin/creds.csv"),',');
  322. List<String[]> csvBody = reader.readAll();
  323. updater = new Scanner(System.in);
  324.  
  325. while(true){
  326. System.out.println("What would you like to update, Password or Email?");
  327. userResponse = updater.next();
  328. userResponse = toTitleCase(userResponse);
  329. if(userResponse.equals("Password")){
  330. pass = true;
  331. break;
  332. }else if (userResponse.equals("Email")){
  333. email = true;
  334. break;
  335. }else {
  336. System.out.println("Invalid Response");
  337. }
  338. }
  339.  
  340. for(String[] creds : csvBody){
  341.  
  342. }
  343. } catch (FileNotFoundException e) {
  344. e.printStackTrace();
  345. } catch (IOException e) {
  346. e.printStackTrace();
  347. }
  348. }
  349.  
  350. private String search() {
  351. return null;
  352.  
  353. }
  354.  
  355. private String login(String username, String password) throws FileNotFoundException {
  356. String type = null;
  357. BufferedReader reader = new BufferedReader(
  358. new FileReader("bin/creds.csv"));
  359. String thisLine;
  360. try {
  361. thisLine = reader.readLine();
  362. while ((thisLine = reader.readLine()) != null) {
  363. thisLine = thisLine.trim();
  364. String[] items = thisLine.split(",");
  365. String user = items[1];
  366. String pass = items[2];
  367. String userType = items[4];
  368. user=user.toLowerCase();
  369. if (user.equals(username)) {
  370. if (pass.equals(password)) {
  371.  
  372. if (userType.equals("Buyer")) {
  373. type = "Buyer";
  374. }else if (userType.equals("Seller")){
  375. type = "Seller";
  376. }else if(userType.equals("MarketPlaceAdmin")){
  377. type = "MarketPlaceAdmin";
  378. }
  379. currentUsername = toTitleCase(user);
  380. loggedin = true;
  381. break;
  382. }
  383. }
  384. }
  385.  
  386. } catch (IOException e) {
  387. System.out.print("\nUser does not exist\n");
  388. e.printStackTrace();
  389. } finally {
  390. try {
  391. reader.close();
  392. } catch (IOException e) {
  393. /* ignore */ }
  394. }
  395. return type;
  396.  
  397. }
  398.  
  399. private String currentUsername(){
  400. return currentUsername;
  401. }
  402.  
  403. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement