Guest User

Untitled

a guest
Dec 1st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.67 KB | None | 0 0
  1. // Include the Axios library for HTTP requests
  2.  
  3.  
  4. import Axios from 'axios';
  5.  
  6.  
  7. var helpers = {
  8.  
  9. // This will save new articles to our database
  10. postSaved: function (prefix, firstName, middleInitial, surname,
  11. streetAddress, city, state, zipCode, emailAddress, username, password,
  12. telephoneNumber, bday) {
  13. var newUser = { Title: prefix,
  14. GivenName: firstName,
  15. MiddleInitial: middleInitial,
  16. Surname: surname,
  17. StreetAddress: streetAddress,
  18. City: city,
  19. State: state,
  20. ZipCode: zipCode,
  21. EmailAddress: emailAddress,
  22. Username:username,
  23. Password:password,
  24. BrowserUserAgent:req.body.BrowserUserAgent,
  25. TelephonNumber: telephoneNumber,
  26. Birthday:bday,
  27. MothersMaiden: null,
  28. Color:null,
  29. Ocupation:req.body.Ocupation,
  30. Company:null,Vehicle:null,
  31. Domain:null,
  32. GUID:null, };
  33.  
  34. return Axios.post("/api/saved", newUser)
  35. .then(function(response) {
  36. console.log("axios results", response.data._id);
  37. return response.data._id;
  38. });
  39. }
  40.  
  41.  
  42.  
  43.  
  44.  
  45. }
  46.  
  47. // Require sibi_americans Schema
  48. const db = require("./server/models");
  49. // -------------------------------------------------
  50. app.post("/api/saved", function(req, res) {
  51. console.log(req.body);
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. db.sibi_americans.create({
  59. Title: req.body.Title,
  60. GivenName: req.body.GivenName,
  61. MiddleInitial: req.body.MiddleInitial,
  62. Surname:req.body.Surname,
  63. StreetAddress: req.body.StreetAddress,
  64. State: req.body.State,
  65. ZipCode: req.body.ZipCode,
  66. City: req.body.City,
  67. EmailAddress: req.body.EmailAddress,
  68. Username: req.body.Username,
  69. Password: req.body.Password,
  70. BrowserUserAgent: req.body.BrowserUserAgent,
  71. TelephoneNumber: req.body.TelephoneNumber,
  72. Birthday: req.body.Birthday,
  73. Color: req.body.Color,
  74. Ocupation: req.body.Ocupation,
  75. Company: req.body.Company,
  76. Vehicle: req.body.Vehicle,
  77. Domain: req.body.Domain,
  78. GUID: req.body.GUID
  79.  
  80.  
  81. }).then(function(dbNewUser) {
  82. // We have access to the new todo as an argument inside of the
  83. callback function
  84. res.json(dbNewUser).catch(err);
  85. });
  86.  
  87. module.exports = function (sequelize, DataTypes) {
  88. var sibi_americans = sequelize.define("sibi_americans", {
  89. Number: {
  90. type: DataTypes.INTEGER,
  91. allowNull: false,
  92. autoIncrement: true,
  93. primaryKey: true,
  94.  
  95. },
  96. Title: {
  97. type: DataTypes.STRING,
  98. allowNull: false,
  99. validate: {
  100. len: [1, 4]
  101. }
  102. },
  103. GivenName: {
  104. type: DataTypes.STRING,
  105. allowNull: false,
  106. validate: {
  107. len: [1, 22]
  108.  
  109. }
  110. },
  111. MiddleInitial: {
  112. type: DataTypes.STRING,
  113. allowNull: false,
  114. validate: {
  115. len: [1, 3]
  116. }
  117. },
  118. Surname: {
  119. type: DataTypes.STRING,
  120. allowNull: false,
  121. validate: {
  122. len: [1, 22]
  123. }
  124. },
  125. StreetAddress: {
  126. type: DataTypes.STRING,
  127. allowNull: false,
  128. validate: {
  129. len: [10]
  130. }
  131. },
  132. City: {
  133. type: DataTypes.STRING,
  134. allowNull: false,
  135. validate: {
  136. len: [1]
  137. }
  138. },
  139. State: {
  140. type: DataTypes.STRING,
  141. allowNull: false,
  142. validate: {
  143. len: [1, 11]
  144. }
  145. },
  146. ZipCode: {
  147. type: DataTypes.STRING,
  148. allowNull: false,
  149. validate: {
  150. len: [5, 10]
  151. }
  152. },
  153.  
  154. EmailAddress: {
  155. type: DataTypes.STRING,
  156. allowNull: false,
  157.  
  158. },
  159. Username: {
  160. type: DataTypes.STRING,
  161. allowNull: false,
  162. validate: {
  163. len: [1, 33]
  164. }
  165. },
  166. Password: {
  167. type: DataTypes.STRING,
  168. allowNull: false,
  169. validate: {
  170. len: [6, 22]
  171. }
  172. },
  173. BrowserUserAgent: {
  174. type: DataTypes.STRING,
  175. allowNull: true
  176.  
  177. },
  178. TelephoneNumber: {
  179. type: DataTypes.STRING,
  180.  
  181. },
  182. Birthday: {
  183. type: DataTypes.STRING,
  184. allowNull: false,
  185. validate: {
  186. len: [8, 10]
  187. }
  188. },
  189. MothersMaiden: {
  190. type: DataTypes.STRING,
  191. allowNull: true
  192. },
  193.  
  194. Color: {
  195. type: DataTypes.STRING,
  196. allowNull: true
  197. },
  198. Occupation: {
  199. type: DataTypes.STRING,
  200. allowNull: true
  201.  
  202. },
  203. Company: {
  204. type: DataTypes.STRING,
  205. allowNull: true,
  206.  
  207. },
  208. Vehicle: {
  209. type: DataTypes.STRING,
  210. allowNull: true
  211. },
  212. Domain: {
  213. type: DataTypes.STRING,
  214. allowNull: true
  215. },
  216. GUID: {
  217. type: DataTypes.STRING,
  218. allowNull: true
  219. },
  220. createdAt: {
  221. type: DataTypes.DATE,
  222. default: Date.now()
  223. },
  224.  
  225. updatedAt: {
  226. type: DataTypes.DATE,
  227. default: Date.now()
  228. }
  229. });
  230. return sibi_americans;
  231. };
  232.  
  233. import React from "react";
  234. import helpers from '../utils/helpers';
  235. class Form extends React.Component {
  236. constructor(props) {
  237. super(props);
  238.  
  239. this.state = {
  240. prefix:"",
  241. firstName: "",
  242. surname: "",
  243. middleInitial: "",
  244. stateOfResidence:"",
  245. streetAddress: "",
  246. city: "",
  247. zipCode:"",
  248. password: "",
  249. password2: "",
  250. username:"",
  251. dob:"",
  252. telephoneNumber: "",
  253. emailAddress:"",
  254. };
  255.  
  256. this.handleChange = this.handleChange.bind(this);
  257. this.handleSubmit = this.handleSubmit.bind(this);
  258. }
  259.  
  260. handleChange(event) {
  261. var newState = {};
  262. newState[event.target.id] = event.target.value;
  263. this.setState(newState);
  264. }
  265.  
  266. handleSubmit(event) {
  267. event.preventDefault();
  268. helpers.postSaved(
  269. this.state.prefix,
  270. this.state.firstName,
  271. this.state.middleInitial,
  272. this.state.surname,
  273. this.state.streetAddress,
  274. this.state.city,
  275. this.state.stateOfResidence,
  276. this.state.zipCode,
  277. this.state.emailAddress,
  278. this.state.username,
  279. this.state.password,
  280. this.state.telephoneNumber,
  281. this.state.dob)
  282. .then(()=> {
  283. console.log("Posted to MongoDB");
  284. });
  285.  
  286. this.setState({
  287. firstName: "",
  288. surname: "",
  289. middleInitial: "",
  290. stateOfResidence:"",
  291. streetAddress: "",
  292. city: "",
  293. zipCode:"",
  294. password: "",
  295. password2: "",
  296. username:"",
  297. dob:"",
  298. emailAddress:"",
  299. telephoneNumber: "",
  300. prefix:"",
  301. });
  302. }
  303.  
  304. render() {
  305.  
  306. return (
  307. <div className="container">
  308. <div className="panel panel-default myPanel">
  309. <div className="panel-heading myPanelHeading">
  310. <h2 className="panel-title text-center ">Registration Form</h2>
  311. </div>
  312. <div className="panel-body text-center">
  313.  
  314. <form onSubmit={this.handleSubmit}>
  315. <div className="form-group">
  316.  
  317. <h4 className="">
  318. <strong>Title</strong>
  319. </h4>
  320.  
  321.  
  322. <input
  323. type="text"
  324. className="form-control text-center"
  325. id="prefix"
  326. value={this.state.prefix}
  327. onChange={this.handleChange}
  328. placeholder="Mr. Mrs. Ms. or Dr."
  329. required
  330. />
  331. <br />
  332. <div className="row">
  333. <div className="col-xs-4">
  334. <h4 className="">
  335. <strong>First name</strong>
  336. </h4>
  337. <input
  338. type="text"
  339. className="form-control text-center"
  340. id="firstName"
  341. value={this.state.firstName}
  342. onChange={this.handleChange}
  343. placeholder="Your first name"
  344. required
  345. /> </div>
  346. <div className="col-xs-4">
  347.  
  348. <h4 className="">
  349. <strong>Middle initial</strong>
  350. </h4>
  351.  
  352.  
  353. <input
  354. type="text"
  355. className="form-control text-center"
  356. id="middleInitial"
  357. value={this.state.middleInitial}
  358. onChange={this.handleChange}
  359. placeholder="Middle initial only"
  360. required
  361. />
  362. </div>
  363. <div className="col-xs-4">
  364.  
  365. <h4 className="">
  366. <strong>Surname</strong>
  367. </h4>
  368.  
  369.  
  370. <input
  371. type="text"
  372. className="form-control text-center"
  373. id="surname"
  374. value={this.state.surname}
  375. onChange={this.handleChange}
  376. placeholder="Your last name"
  377. required
  378. />
  379.  
  380. </div></div>
  381. <br />
  382.  
  383. <h4 className="">
  384. <strong>Street Address</strong>
  385. </h4>
  386. <input
  387. type="text"
  388. className="form-control text-center"
  389. id="streetAddress"
  390. value={this.state.streetAddress}
  391. onChange={this.handleChange}
  392. placeholder="12345 your house blvd"
  393. required
  394. />
  395. <br />
  396. <div className="row">
  397. <div className="col-xs-4">
  398. <h4 className="">
  399. <strong>City</strong>
  400. </h4>
  401. <input
  402. type="text"
  403. className="form-control text-center"
  404. id="city"
  405. value={this.state.city}
  406. onChange={this.handleChange}
  407. placeholder="City of residence"
  408. required
  409. /></div>
  410. <div className="col-xs-4">
  411.  
  412. <h4 className="">
  413. <strong>State</strong>
  414. </h4>
  415. <input
  416. type="text"
  417. className="form-control text-center"
  418. id="stateOfResidence"
  419. value={this.state.stateOfResidence}
  420. onChange={this.handleChange}
  421. placeholder="State"
  422. required
  423. />
  424. </div>
  425. <div className="col-xs-4">
  426. <h4 className="">
  427. <strong>Zip Code</strong>
  428. </h4>
  429. <input
  430. type="text"
  431. className="form-control text-center"
  432. id="zipCode"
  433. value={this.state.zipCode}
  434. onChange={this.handleChange}
  435. placeholder="33445"
  436. required
  437. />
  438. </div>
  439. </div>
  440. <br />
  441. <h4 className="">
  442. <strong>Date of birth</strong>
  443. </h4>
  444.  
  445.  
  446. <input
  447. type="text"
  448. className="form-control text-center"
  449. id="dob"
  450. value={this.state.dob}
  451. onChange={this.handleChange}
  452. placeholder="01/02/2003"
  453. required
  454.  
  455. />
  456. <br />
  457. <h4 className="">
  458. <strong>Telephone number</strong>
  459. </h4>
  460.  
  461.  
  462. <input
  463. type="text"
  464. className="form-control text-center"
  465. id="telephoneNumber"
  466. value={this.state.telephoneNumber}
  467. onChange={this.handleChange}
  468. placeholder="480-212-2121"
  469. required
  470.  
  471. />
  472. <br />
  473. <h4 className="">
  474. <strong>Email Address</strong>
  475. </h4>
  476.  
  477.  
  478. <input
  479. type="text"
  480. className="form-control text-center"
  481. id="emailAddress"
  482. value={this.state.emailAddress}
  483. onChange={this.handleChange}
  484. placeholder="you@yourEmailAddress.com"
  485. required
  486.  
  487. />
  488. <br />
  489. <h4 className="">
  490. <strong>Username</strong>
  491. </h4>
  492.  
  493.  
  494. <input
  495. type="text"
  496. className="form-control text-center"
  497. id="username"
  498. value={this.state.username}
  499. onChange={this.handleChange}
  500. placeholder="Your Sibi Username"
  501. required
  502.  
  503. />
  504. <br />
  505. <h4 className="">
  506. <strong>Password</strong>
  507. </h4>
  508.  
  509.  
  510. <input
  511. type="password"
  512. className="form-control text-center"
  513. id="password"
  514. value={this.state.password}
  515. onChange={this.handleChange}
  516. placeholder="Insert Super strong password here"
  517. required
  518.  
  519. />
  520. <br />
  521. <h4 className="">
  522. <strong>Confirm your password</strong>
  523. </h4>
  524.  
  525.  
  526. <input
  527. type="password"
  528. className="form-control text-center"
  529. id="password2"
  530. value={this.state.password2}
  531. onChange={this.handleChange}
  532. placeholder="They must match"
  533. required
  534.  
  535. />
  536. <br />
  537.  
  538.  
  539.  
  540.  
  541.  
  542. <button
  543. type="submit"
  544. className="btn submit-btn"
  545. >
  546. Submit
  547. </button>
  548.  
  549. </div>
  550. </form>
  551. </div>
  552. </div></div>
  553. );
  554. }
  555. }
Add Comment
Please, Sign In to add comment