Emmanuil 4 лет назад
Родитель
Сommit
552b526d25

+ 3 - 1
myproject/src/App.js

@@ -8,9 +8,10 @@ import { store } from "./store/store";
 import Login from "./signIn/signIn";
 import Register from "./signUp/signUp";
 import putPassword from "./putPassword/putPassword";
-import MyProfile from "./myProfile/myProfile";
+import MyProfile from "./myProfile/myProfile"
 
 const App = (props) => {
+  console.log(props);
   return (
     <Provider store={store}>
       <Router history={history}>
@@ -20,6 +21,7 @@ const App = (props) => {
             <Route exact path="/sign_up" component={Register} />
             <Route exact path="/put_password" component={putPassword} />
             <Route exact path="/my_profile" component={MyProfile} />
+            <Route exact path="/my_profile/:id" component={MyProfile} />
           </div>
         </Switch>
       </Router>

+ 3 - 2
myproject/src/myProfile/myProfile.js

@@ -45,7 +45,7 @@ class MyProfile1 extends Component {
   }
 
   componentDidMount() {
-    const a = localStorage.getItem("id");
+    const a = localStorage.getItem("id")
     this.props.chatGroup(a);
     this.props.message();
     // const ar = localStorage.getItem("a");
@@ -82,8 +82,9 @@ class MyProfile1 extends Component {
             <div className="chat-groups">
               {this.way1("users", "getUser") ||
                 this.way("chatGroup", "getAllChatGroupsOneUser", (el) => {
+                  console.log(el)
                   return (
-                    <div key={el.id} onClick={() => console.log(this.state.idChat)}>
+                    <div key={el.id} onClick={() => history.push(`/my_profile/${el.id}`)}>
                       <ChatGroupsBar
                         id={el.id}
                         login={

+ 2 - 37
myproject/src/putPassword/actionPutPassword/actionPutPassword.js

@@ -1,32 +1,5 @@
 import { actionPromise, store } from "../../store/store";
-
-// store.dispatch({
-//   type: "PROMISE",
-//   name: "login",
-//   status: "RESOLVED",
-//   payload: "hi",
-// });
-
-// store.dispatch({
-//   type: "PROMISE",
-//   name: "chatList",
-//   status: "REJECTED",
-//   error: "bye",
-// });
-
-// function actionToken(token) {
-//   return {
-//     type: "TOKEN",
-//     token,
-//   };
-// }
-
-// function actionError(error) {
-//   return {
-//     type: "ERROR",
-//     error,
-//   };
-// }
+import history from '../../history';
 
 const getGQL = (url, headers = {}) => (query = "", variables = {}) =>
   fetch(url, {
@@ -47,20 +20,12 @@ const actionPutPasswordPromise = (email, password) => {
     { email, password }
   );
     return actionPromise("putPassword", promise);
-  // return actionPromise("login", promise);
 };
 
 const actionPutPassword = (email, password) => {
   return async (dispatch) => {
     let token = await dispatch(actionPutPasswordPromise(email, password));
-    console.log(token);
-    // if (!token.errors) {
-    //   const a = dispatch(actionToken(token));
-    //   console.log(a);
-    // } else {
-    //   const b = dispatch(actionError(token));
-    //   console.log(b);
-    // }
+    if(token.data.changePassword.login !== null) history.push("/")
   };
 };
 

+ 1 - 63
myproject/src/signIn/actionLogin/actionLogin.js

@@ -1,37 +1,6 @@
 import { actionPromise, store } from "../../store/store";
 import history from '../../history';
 
-// store.dispatch({
-//   type: "PROMISE",
-//   name: "login",
-//   status: "RESOLVED",
-//   payload: "hi",
-// });
-
-// store.dispatch({
-//   type: "PROMISE",
-//   name: "chatList",
-//   status: "REJECTED",
-//   error: "bye",
-// });
-
-// function actionToken(token) {
-//   return {
-//     type: "TOKEN",
-//     token,
-//   };
-// }
-
-// function actionError(error) {
-//   return {
-//     type: "ERROR",
-//     error,
-//   };
-// }
-
-// const handleClick = () => history.push("/my_profile")
-
-
 const getGQL = (url, headers = {}) => (query = "", variables = {}) =>
   fetch(url, {
     method: "POST",
@@ -42,13 +11,6 @@ const getGQL = (url, headers = {}) => (query = "", variables = {}) =>
     },
     body: JSON.stringify({ query, variables }),
   }).then((res) => res.json())
-// .then((a) => {
-//   if (a.data.getLogin !== null) {
-//     history.push("/my_profile")
-//     // handleClick()
-//     // window.location.assign("/my_profile")
-//   };
-// });
 
 const actionLoginPromise =  (login, password) => {
   var promise =  getGQL("http://localhost:3330/graphql")(
@@ -60,35 +22,11 @@ const actionLoginPromise =  (login, password) => {
   return actionPromise("login", promise);
 };
 
-// const actionLoginPromise1 =  (login, password) => {
-//   var promise =  getGQL("http://localhost:3330/graphql")(
-//     `query l($login:String, $password:String){
-//         getLogin(login:$login, password:$password)
-//         }`,
-//     { login, password }
-//   )
-//   return actionPromise("error", promise);
-// };
-
 const actionLogin = (login, password) => {
   return async (dispatch) => {
     var token = await dispatch(actionLoginPromise(login, password));
-    console.log(token);
-    // if (token === undefined) await dispatch(actionLoginPromise1(login, password))
-    if(token) history.push("/my_profile")
+    if(token.data.getLogin !== null) history.push("/my_profile")
   };
 };
 
-// const mapStateToProps = (comp) => {
-//   switch (comp) {
-//     case "1":
-//       return function (state) {
-//         return { a: state.login };
-//       };
-
-//     default:
-//       return undefined;
-//   }
-// };
-
 export { actionLogin };

+ 43 - 50
server/index.js

@@ -7,6 +7,7 @@ const { graphqlHTTP } = require("express-graphql");
 const { buildSchema } = require("graphql");
 const cors = require("cors");
 const expressJwt = require("express-jwt");
+const sha1 = require("sha1");
 // const mailer = require("./smtpGmail");
 const app = express();
 
@@ -42,8 +43,14 @@ class User extends Sequelize.Model {
 User.init(
   {
     email: Sequelize.STRING,
-    password: Sequelize.STRING,
+    // password: Sequelize.STRING,
     login: Sequelize.STRING,
+    password: {
+      type: Sequelize.STRING,
+      set(value) {
+        this.setDataValue("password", sha1(value));
+      },
+    },
   },
   { sequelize, modelName: "user" }
 );
@@ -56,7 +63,18 @@ class Message extends Sequelize.Model {
 
 Message.init(
   { message: Sequelize.STRING },
-  { sequelize, modelName: "message" }
+  {
+    scopes: {
+      deleted: {
+        where: {
+          id: 1
+        },
+      },
+    },
+
+    sequelize,
+    modelName: "message",
+  }
 );
 
 class ChatGroup extends Sequelize.Model {}
@@ -76,7 +94,6 @@ ChatGroup.belongsTo(User, { as: "autor", sourceKey: "autorId" });
 ChatGroup.belongsTo(User, { as: "partner", sourceKey: "partnerId" });
 
 const secret = `7.!BMB?Y+Bc2vZE-Hb5YuCT6QvE^FN,JWN6M?_VtFXeC5dLtB!`;
-const secretPass = "JcFWhuLkpaK9aB3Gtbvo2Y0BApdw5q1tUyAyJeD8fJXs78d7zR";
 
 const authenticate = async ({ login, password }) => {
   const user = await User.findOne({ where: { login, password } });
@@ -101,7 +118,8 @@ var schema = buildSchema(`
     getAllChatGroupsOneUser(id: ID!): [ChatGroup]
   }
   type Mutation {
-    createUser(email: String, password: String, login: String): User
+    deleteUser(id: ID!): String
+    createUser(email: String, login: String, password: String): User
     changePassword(email: String, password: String): User
     createMessage(message: String, autorId: String, partnerId: String): Message
     changeMessage(id: ID!, message: String): Message
@@ -133,26 +151,40 @@ var schema = buildSchema(`
 const getUser = async ({ email }) => await User.findOne({ where: { email } });
 
 const getLogin = async ({ login, password }) => {
-  const userFind = await User.findOne({ where: { login, password } });
+  const passwordSha1 = sha1(password);
+  const userFind = await User.findOne({
+    where: { login, password: passwordSha1 },
+  });
   return authenticate(userFind);
 };
 
-const createUser = async ({ email, password, login }) => {
+const createUser = async ({ email, login, password }) => {
   const wasUserCreated = await User.findOne({ where: { email } });
   if (!wasUserCreated) {
-    // const passwordModification = jwt.sign(password + secretPass, secret);
-    const user = { email, password, login };
+    const user = { email, login, password };
     const newUser = new User(user);
     await newUser.save();
     return await User.findOne({ where: { login } });
   } else console.error("error");
 };
 
+const deleteUser = async ({ id }) => {
+  const userFind = await User.findByPk(id);
+  if (userFind) {
+    await User.destroy({ where: { id } });
+    return "User deleted";
+  } else return "User not find";
+};
+
 const changePassword = async ({ email, password }) => {
   var userFind = await User.findOne({ where: { email } });
   if (userFind) {
-    await User.update({ password }, { where: { email } });
+    const a = await User.update(
+      { password, login: userFind.login },
+      { where: { email } }
+    );
     userFind.email = "The password has been change";
+    console.log(a);
     return userFind;
   } else {
     userFind = { email: "Email not found" };
@@ -243,6 +275,7 @@ const changeMessage = async ({ id, message }) => {
 };
 
 const deleteMessage = async ({ id }) => {
+  // await Message.scope("deleted").findByPk(id);
   const messFind = await Message.findByPk(id);
   if (messFind) {
     await Message.destroy({ where: { id } });
@@ -337,6 +370,7 @@ var root = {
   getUser,
   getLogin,
   createUser,
+  deleteUser,
   getAllUsers,
   getMessage,
   changePassword,
@@ -364,31 +398,6 @@ app.get("/users", async (req, res) => res.send(await User.findAll()));
 app.get("/message", async (req, res) => res.send(await Message.findAll()));
 app.get("/chat-group", async (req, res) => res.send(await ChatGroup.findAll()));
 
-// app.post("/users", async (req, res) => {
-//   // const twoUsers = async () => {
-//   //   const userEmail = await User.findOne({ where: { email: req.body.email } });
-//   //   if (userEmail !== null) console.log(err);
-//   //   else {
-//   //     console.log("hi");
-//   var newUser = new User(req.body);
-//   // const message = {
-//   //   to: req.body.email,
-//   //   subject: "Registered",
-//   //   text: `Отлично. Вот ваши данные:
-//   //   login: ${req.body.email}
-//   //   password: ${req.body.password}
-
-//   //   Перейдите по ссылке, чтобы войти в свой аккаунт
-//   //   url: http://localhost:3335/sign_in`,
-//   // };
-//   // mailer(message);
-//   await newUser.save();
-//   res.status(201).send(newUser);
-//   // }
-//   // };
-//   // twoUsers();
-// });
-
 // function errorHandler(err, req, res, next) {
 //   if (typeof err === "string") {
 //     return res.status(400).json({ message: err });
@@ -415,22 +424,6 @@ app.post("/users/authenticate", async (req, res, next) => {
 
 // app.use(jwtWare());
 
-app.get("/a", (req, res, next) => {
-  console.log(req.headers.authorization);
-  const token1 = req.headers.authorization;
-  console.log(token1);
-  // if (token) {
-  const data = jwt.verify(token1, secret);
-  console.log(data);
-  // if (data) {
-  console.log(data.sub.login);
-  res.send(`<h1>Hello ${data.sub.login}</h1>`);
-  // } else {
-  //   res.send(`<h1>Hello haker</h1>`);
-  // }
-  // }
-});
-
 // (async () => {
 //   let persone =
 // //   await User.findOne({ where: { login: "B" } }) ||

+ 27 - 0
server/node_modules/charenc/LICENSE.mkd

@@ -0,0 +1,27 @@
+Copyright © 2011, Paul Vorbach. All rights reserved.
+Copyright © 2009, Jeff Mott. All rights reserved.
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright notice, this
+  list of conditions and the following disclaimer in the documentation and/or
+  other materials provided with the distribution.
+* Neither the name Crypto-JS nor the names of its contributors may be used to
+  endorse or promote products derived from this software without specific prior
+  written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 1 - 0
server/node_modules/charenc/README.js

@@ -0,0 +1 @@
+**enc** provides crypto character encoding utilities.

+ 33 - 0
server/node_modules/charenc/charenc.js

@@ -0,0 +1,33 @@
+var charenc = {
+  // UTF-8 encoding
+  utf8: {
+    // Convert a string to a byte array
+    stringToBytes: function(str) {
+      return charenc.bin.stringToBytes(unescape(encodeURIComponent(str)));
+    },
+
+    // Convert a byte array to a string
+    bytesToString: function(bytes) {
+      return decodeURIComponent(escape(charenc.bin.bytesToString(bytes)));
+    }
+  },
+
+  // Binary encoding
+  bin: {
+    // Convert a string to a byte array
+    stringToBytes: function(str) {
+      for (var bytes = [], i = 0; i < str.length; i++)
+        bytes.push(str.charCodeAt(i) & 0xFF);
+      return bytes;
+    },
+
+    // Convert a byte array to a string
+    bytesToString: function(bytes) {
+      for (var str = [], i = 0; i < bytes.length; i++)
+        str.push(String.fromCharCode(bytes[i]));
+      return str.join('');
+    }
+  }
+};
+
+module.exports = charenc;

+ 54 - 0
server/node_modules/charenc/package.json

@@ -0,0 +1,54 @@
+{
+  "_from": "charenc@>= 0.0.1",
+  "_id": "charenc@0.0.2",
+  "_inBundle": false,
+  "_integrity": "sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc=",
+  "_location": "/charenc",
+  "_phantomChildren": {},
+  "_requested": {
+    "type": "range",
+    "registry": true,
+    "raw": "charenc@>= 0.0.1",
+    "name": "charenc",
+    "escapedName": "charenc",
+    "rawSpec": ">= 0.0.1",
+    "saveSpec": null,
+    "fetchSpec": ">= 0.0.1"
+  },
+  "_requiredBy": [
+    "/sha1"
+  ],
+  "_resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz",
+  "_shasum": "c0a1d2f3a7092e03774bfa83f14c0fc5790a8667",
+  "_spec": "charenc@>= 0.0.1",
+  "_where": "E:\\a-level\\project_js2\\server\\node_modules\\sha1",
+  "author": {
+    "name": "Paul Vorbach",
+    "email": "paul@vorb.de",
+    "url": "http://vorb.de"
+  },
+  "bugs": {
+    "url": "https://github.com/pvorb/node-charenc/issues"
+  },
+  "bundleDependencies": false,
+  "deprecated": false,
+  "description": "character encoding utilities",
+  "engines": {
+    "node": "*"
+  },
+  "homepage": "https://github.com/pvorb/node-charenc#readme",
+  "license": "BSD-3-Clause",
+  "main": "charenc.js",
+  "name": "charenc",
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/pvorb/node-charenc.git"
+  },
+  "tags": [
+    "utf8",
+    "binary",
+    "byte",
+    "string"
+  ],
+  "version": "0.0.2"
+}

+ 27 - 0
server/node_modules/crypt/LICENSE.mkd

@@ -0,0 +1,27 @@
+Copyright © 2011, Paul Vorbach. All rights reserved.
+Copyright © 2009, Jeff Mott. All rights reserved.
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright notice, this
+  list of conditions and the following disclaimer in the documentation and/or
+  other materials provided with the distribution.
+* Neither the name Crypto-JS nor the names of its contributors may be used to
+  endorse or promote products derived from this software without specific prior
+  written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 1 - 0
server/node_modules/crypt/README.mkd

@@ -0,0 +1 @@
+**crypt** provides utilities for encryption and hashing

+ 96 - 0
server/node_modules/crypt/crypt.js

@@ -0,0 +1,96 @@
+(function() {
+  var base64map
+      = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
+
+  crypt = {
+    // Bit-wise rotation left
+    rotl: function(n, b) {
+      return (n << b) | (n >>> (32 - b));
+    },
+
+    // Bit-wise rotation right
+    rotr: function(n, b) {
+      return (n << (32 - b)) | (n >>> b);
+    },
+
+    // Swap big-endian to little-endian and vice versa
+    endian: function(n) {
+      // If number given, swap endian
+      if (n.constructor == Number) {
+        return crypt.rotl(n, 8) & 0x00FF00FF | crypt.rotl(n, 24) & 0xFF00FF00;
+      }
+
+      // Else, assume array and swap all items
+      for (var i = 0; i < n.length; i++)
+        n[i] = crypt.endian(n[i]);
+      return n;
+    },
+
+    // Generate an array of any length of random bytes
+    randomBytes: function(n) {
+      for (var bytes = []; n > 0; n--)
+        bytes.push(Math.floor(Math.random() * 256));
+      return bytes;
+    },
+
+    // Convert a byte array to big-endian 32-bit words
+    bytesToWords: function(bytes) {
+      for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8)
+        words[b >>> 5] |= bytes[i] << (24 - b % 32);
+      return words;
+    },
+
+    // Convert big-endian 32-bit words to a byte array
+    wordsToBytes: function(words) {
+      for (var bytes = [], b = 0; b < words.length * 32; b += 8)
+        bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF);
+      return bytes;
+    },
+
+    // Convert a byte array to a hex string
+    bytesToHex: function(bytes) {
+      for (var hex = [], i = 0; i < bytes.length; i++) {
+        hex.push((bytes[i] >>> 4).toString(16));
+        hex.push((bytes[i] & 0xF).toString(16));
+      }
+      return hex.join('');
+    },
+
+    // Convert a hex string to a byte array
+    hexToBytes: function(hex) {
+      for (var bytes = [], c = 0; c < hex.length; c += 2)
+        bytes.push(parseInt(hex.substr(c, 2), 16));
+      return bytes;
+    },
+
+    // Convert a byte array to a base-64 string
+    bytesToBase64: function(bytes) {
+      for (var base64 = [], i = 0; i < bytes.length; i += 3) {
+        var triplet = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
+        for (var j = 0; j < 4; j++)
+          if (i * 8 + j * 6 <= bytes.length * 8)
+            base64.push(base64map.charAt((triplet >>> 6 * (3 - j)) & 0x3F));
+          else
+            base64.push('=');
+      }
+      return base64.join('');
+    },
+
+    // Convert a base-64 string to a byte array
+    base64ToBytes: function(base64) {
+      // Remove non-base-64 characters
+      base64 = base64.replace(/[^A-Z0-9+\/]/ig, '');
+
+      for (var bytes = [], i = 0, imod4 = 0; i < base64.length;
+          imod4 = ++i % 4) {
+        if (imod4 == 0) continue;
+        bytes.push(((base64map.indexOf(base64.charAt(i - 1))
+            & (Math.pow(2, -2 * imod4 + 8) - 1)) << (imod4 * 2))
+            | (base64map.indexOf(base64.charAt(i)) >>> (6 - imod4 * 2)));
+      }
+      return bytes;
+    }
+  };
+
+  module.exports = crypt;
+})();

+ 52 - 0
server/node_modules/crypt/package.json

@@ -0,0 +1,52 @@
+{
+  "_from": "crypt@>= 0.0.1",
+  "_id": "crypt@0.0.2",
+  "_inBundle": false,
+  "_integrity": "sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs=",
+  "_location": "/crypt",
+  "_phantomChildren": {},
+  "_requested": {
+    "type": "range",
+    "registry": true,
+    "raw": "crypt@>= 0.0.1",
+    "name": "crypt",
+    "escapedName": "crypt",
+    "rawSpec": ">= 0.0.1",
+    "saveSpec": null,
+    "fetchSpec": ">= 0.0.1"
+  },
+  "_requiredBy": [
+    "/sha1"
+  ],
+  "_resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
+  "_shasum": "88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b",
+  "_spec": "crypt@>= 0.0.1",
+  "_where": "E:\\a-level\\project_js2\\server\\node_modules\\sha1",
+  "author": {
+    "name": "Paul Vorbach",
+    "email": "paul@vorb.de",
+    "url": "http://vorb.de"
+  },
+  "bugs": {
+    "url": "https://github.com/pvorb/node-crypt/issues"
+  },
+  "bundleDependencies": false,
+  "deprecated": false,
+  "description": "utilities for encryption and hashing",
+  "engines": {
+    "node": "*"
+  },
+  "homepage": "https://github.com/pvorb/node-crypt#readme",
+  "license": "BSD-3-Clause",
+  "main": "crypt.js",
+  "name": "crypt",
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/pvorb/node-crypt.git"
+  },
+  "tags": [
+    "hash",
+    "security"
+  ],
+  "version": "0.0.2"
+}

+ 1 - 0
server/node_modules/sha1/.npmignore

@@ -0,0 +1 @@
+node_modules/mocha

+ 4 - 0
server/node_modules/sha1/.travis.yml

@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+  - 0.6
+  - 0.8

+ 27 - 0
server/node_modules/sha1/LICENSE

@@ -0,0 +1,27 @@
+Copyright © 2009, Jeff Mott. All rights reserved.
+Copyright © 2011, Paul Vorbach. All rights reserved.
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright notice, this
+  list of conditions and the following disclaimer in the documentation and/or
+  other materials provided with the distribution.
+* Neither the name Crypto-JS nor the names of its contributors may be used to
+  endorse or promote products derived from this software without specific prior
+  written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 88 - 0
server/node_modules/sha1/README.md

@@ -0,0 +1,88 @@
+sha1
+====
+
+[![build
+status](https://secure.travis-ci.org/pvorb/node-sha1.png)](http://travis-ci.org/pvorb/node-sha1)
+
+a native js function for hashing messages with the SHA-1 algorithm
+
+
+Installation
+------------
+
+    npm install sha1
+
+or
+
+    ender build sha1
+
+
+Example
+-------
+
+~~~ javascript
+var sha1 = require('sha1');
+
+sha1("message");
+~~~
+
+This will return the string:
+
+    "6f9b9af3cd6e8b8a73c2cdced37fe9f59226e27d"
+
+
+API
+---
+
+### sha1(msg)
+
+Returns the SHA-1 hash of the given message.
+
+  * `msg` String -- the message that you want to hash.
+
+It's as simple as that.
+
+
+Credits
+-------
+
+This function is taken from [CryptoJS](http://code.google.com/p/crypto-js/).
+This package only provides easy access to a javascript-only version of the SHA-1
+algorithm over npm.
+
+
+License
+-------
+
+(New BSD License /
+[BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause))
+
+~~~
+Copyright © 2009, Jeff Mott. All rights reserved.
+Copyright © 2011, Paul Vorbach. All rights reserved.
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright notice, this
+  list of conditions and the following disclaimer in the documentation and/or
+  other materials provided with the distribution.
+* Neither the name Crypto-JS nor the names of its contributors may be used to
+  endorse or promote products derived from this software without specific prior
+  written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+~~~

+ 67 - 0
server/node_modules/sha1/package.json

@@ -0,0 +1,67 @@
+{
+  "_from": "sha1",
+  "_id": "sha1@1.1.1",
+  "_inBundle": false,
+  "_integrity": "sha1-rdqnqTFo85PxnrKxUJFhjicA+Eg=",
+  "_location": "/sha1",
+  "_phantomChildren": {},
+  "_requested": {
+    "type": "tag",
+    "registry": true,
+    "raw": "sha1",
+    "name": "sha1",
+    "escapedName": "sha1",
+    "rawSpec": "",
+    "saveSpec": null,
+    "fetchSpec": "latest"
+  },
+  "_requiredBy": [
+    "#USER",
+    "/"
+  ],
+  "_resolved": "https://registry.npmjs.org/sha1/-/sha1-1.1.1.tgz",
+  "_shasum": "addaa7a93168f393f19eb2b15091618e2700f848",
+  "_spec": "sha1",
+  "_where": "E:\\a-level\\project_js2\\server",
+  "author": {
+    "name": "Paul Vorbach",
+    "email": "paul@vorb.de",
+    "url": "http://vorb.de"
+  },
+  "bugs": {
+    "url": "https://github.com/pvorb/node-sha1/issues"
+  },
+  "bundleDependencies": false,
+  "dependencies": {
+    "charenc": ">= 0.0.1",
+    "crypt": ">= 0.0.1"
+  },
+  "deprecated": false,
+  "description": "native js function for hashing messages with SHA-1",
+  "devDependencies": {
+    "mocha": "~ 1.4.2"
+  },
+  "engines": {
+    "node": "*"
+  },
+  "homepage": "https://github.com/pvorb/node-sha1#readme",
+  "license": "BSD-3-Clause",
+  "main": "sha1.js",
+  "name": "sha1",
+  "optionalDependencies": {},
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/pvorb/node-sha1.git"
+  },
+  "scripts": {
+    "test": "mocha"
+  },
+  "tags": [
+    "sha1",
+    "hash",
+    "encryption",
+    "native",
+    "secure hashing algorithm"
+  ],
+  "version": "1.1.1"
+}

+ 82 - 0
server/node_modules/sha1/sha1.js

@@ -0,0 +1,82 @@
+(function() {
+  var crypt = require('crypt'),
+      utf8 = require('charenc').utf8,
+      bin = require('charenc').bin,
+
+  // The core
+  sha1 = function (message) {
+    // Convert to byte array
+    if (message.constructor == String)
+      message = utf8.stringToBytes(message);
+    else if (typeof Buffer !== 'undefined' && typeof Buffer.isBuffer == 'function' && Buffer.isBuffer(message))
+      message = Array.prototype.slice.call(message, 0);
+    else if (!Array.isArray(message))
+      message = message.toString();
+
+    // otherwise assume byte array
+
+    var m  = crypt.bytesToWords(message),
+        l  = message.length * 8,
+        w  = [],
+        H0 =  1732584193,
+        H1 = -271733879,
+        H2 = -1732584194,
+        H3 =  271733878,
+        H4 = -1009589776;
+
+    // Padding
+    m[l >> 5] |= 0x80 << (24 - l % 32);
+    m[((l + 64 >>> 9) << 4) + 15] = l;
+
+    for (var i = 0; i < m.length; i += 16) {
+      var a = H0,
+          b = H1,
+          c = H2,
+          d = H3,
+          e = H4;
+
+      for (var j = 0; j < 80; j++) {
+
+        if (j < 16)
+          w[j] = m[i + j];
+        else {
+          var n = w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16];
+          w[j] = (n << 1) | (n >>> 31);
+        }
+
+        var t = ((H0 << 5) | (H0 >>> 27)) + H4 + (w[j] >>> 0) + (
+                j < 20 ? (H1 & H2 | ~H1 & H3) + 1518500249 :
+                j < 40 ? (H1 ^ H2 ^ H3) + 1859775393 :
+                j < 60 ? (H1 & H2 | H1 & H3 | H2 & H3) - 1894007588 :
+                         (H1 ^ H2 ^ H3) - 899497514);
+
+        H4 = H3;
+        H3 = H2;
+        H2 = (H1 << 30) | (H1 >>> 2);
+        H1 = H0;
+        H0 = t;
+      }
+
+      H0 += a;
+      H1 += b;
+      H2 += c;
+      H3 += d;
+      H4 += e;
+    }
+
+    return [H0, H1, H2, H3, H4];
+  },
+
+  // Public API
+  api = function (message, options) {
+    var digestbytes = crypt.wordsToBytes(sha1(message));
+    return options && options.asBytes ? digestbytes :
+        options && options.asString ? bin.bytesToString(digestbytes) :
+        crypt.bytesToHex(digestbytes);
+  };
+
+  api._blocksize = 16;
+  api._digestsize = 20;
+
+  module.exports = api;
+})();

+ 25 - 0
server/node_modules/sha1/test.js

@@ -0,0 +1,25 @@
+var sha1 = require('./sha1.js');
+var assert = require('assert');
+
+describe('sha1', function () {
+  it ('should return the expected SHA-1 hash for "message"', function () {
+    assert.equal('6f9b9af3cd6e8b8a73c2cdced37fe9f59226e27d', sha1('message'));
+  });
+
+  it('should not return the same hash for random numbers twice', function () {
+    var msg1 = Math.floor((Math.random() * 100000) + 1) + (new Date).getTime();
+    var msg2 = Math.floor((Math.random() * 100000) + 1) + (new Date).getTime();
+
+    if (msg1 !== msg2)
+      assert.notEqual(sha1(msg1), sha1(msg2));
+    else
+      assert.equal(sha1(msg1), sha1(msg1));
+  });
+
+  it('should node.js Buffer', function() {
+
+    var buffer = new Buffer('hello, sha1', 'utf8');
+
+    assert.equal(sha1(buffer), sha1('hello, sha1'));
+  })
+});

+ 19 - 0
server/package-lock.json

@@ -301,6 +301,11 @@
       "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz",
       "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA=="
     },
+    "charenc": {
+      "version": "0.0.2",
+      "resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz",
+      "integrity": "sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc="
+    },
     "chokidar": {
       "version": "3.4.0",
       "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.4.0.tgz",
@@ -455,6 +460,11 @@
         "which": "^2.0.1"
       }
     },
+    "crypt": {
+      "version": "0.0.2",
+      "resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
+      "integrity": "sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs="
+    },
     "crypto-random-string": {
       "version": "2.0.0",
       "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz",
@@ -1980,6 +1990,15 @@
       "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
       "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
     },
+    "sha1": {
+      "version": "1.1.1",
+      "resolved": "https://registry.npmjs.org/sha1/-/sha1-1.1.1.tgz",
+      "integrity": "sha1-rdqnqTFo85PxnrKxUJFhjicA+Eg=",
+      "requires": {
+        "charenc": ">= 0.0.1",
+        "crypt": ">= 0.0.1"
+      }
+    },
     "shebang-command": {
       "version": "2.0.0",
       "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",

+ 2 - 1
server/package.json

@@ -23,6 +23,7 @@
     "mysql2": "^2.1.0",
     "nodemon": "^2.0.4",
     "react-router-dom": "^5.2.0",
-    "sequelize": "^6.3.0"
+    "sequelize": "^6.3.0",
+    "sha1": "^1.1.1"
   }
 }