@ -0,0 +1,3 @@ |
|||
module.exports = { |
|||
'passwordHash': 'Bzij4hEeEUpmXTWyS+X0LR+YcA8WFjP2P7qhW0sxA6s='/*password raw: adminPassword*/ |
|||
}; |
@ -0,0 +1,106 @@ |
|||
var request = require('request'); |
|||
|
|||
var url = "http://127.0.0.1:3000/api"; |
|||
var users = [{ |
|||
username: "u1", |
|||
password: "u1", |
|||
email: "u1" |
|||
}, |
|||
{ |
|||
username: "u2", |
|||
password: "u2", |
|||
email: "u2" |
|||
}, |
|||
{ |
|||
username: "u3", |
|||
password: "u3", |
|||
email: "u3" |
|||
} |
|||
]; |
|||
//signup
|
|||
function signup(user) { |
|||
var data = { |
|||
username: user.username, |
|||
password: user.password, |
|||
email: user.email |
|||
}; |
|||
request({ |
|||
url: url + "/signup", |
|||
method: "POST", |
|||
headers: { |
|||
'content-type': 'application/json' |
|||
}, |
|||
body: data, |
|||
json: true |
|||
}, function(err, httpResponse, body) { |
|||
if (err) { |
|||
console.log(err); |
|||
} else { |
|||
//console.log(body);
|
|||
login(user); |
|||
} |
|||
}); |
|||
} |
|||
//login
|
|||
function login(user) { |
|||
var data = { |
|||
username: user.username, |
|||
password: user.email |
|||
}; |
|||
request({ |
|||
url: url + "/login", |
|||
method: "POST", |
|||
headers: { |
|||
'content-type': 'application/json' |
|||
}, |
|||
body: data, |
|||
json: true |
|||
}, function(err, httpResponse, body) { |
|||
if (err) { |
|||
console.log(err); |
|||
} else { |
|||
console.log(body.token); |
|||
user.token = JSON.parse(JSON.stringify(body.token)); |
|||
console.log(user.username); |
|||
addTravel(user); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
function addTravel(user) { |
|||
var data = { |
|||
title: "travel", |
|||
description: "description4", |
|||
from: "placeA", |
|||
to: "placeB", |
|||
date: "2017-10-29T22:58:59.000Z", |
|||
seats: 3, |
|||
package: true, |
|||
collectivized: true, |
|||
type: "offer" |
|||
}; |
|||
request({ |
|||
url: url + "/login", |
|||
method: "POST", |
|||
headers: { |
|||
'content-type': 'application/json', |
|||
'x-access-token': user.token |
|||
}, |
|||
body: data, |
|||
json: true |
|||
}, function(err, httpResponse, body) { |
|||
if (err) { |
|||
console.log(err); |
|||
} else { |
|||
console.log(body); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
for (var i = 0; i < users.length; i++) { |
|||
console.log(i); |
|||
console.log(users[i].username); |
|||
setTimeout(function() { |
|||
signup(users[i]); |
|||
}, 2000); |
|||
} |
@ -0,0 +1,3 @@ |
|||
{ |
|||
"url": "http://localhost:3000/api" |
|||
} |
@ -0,0 +1,15 @@ |
|||
package main |
|||
|
|||
import "fmt" |
|||
|
|||
func main() { |
|||
|
|||
readConfig() |
|||
fmt.Println(config) |
|||
readUsers() |
|||
fmt.Println(users) |
|||
|
|||
user := signup(users[0]) |
|||
user = login(users[0]) |
|||
fmt.Println(user) |
|||
} |
@ -0,0 +1,39 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"encoding/json" |
|||
"fmt" |
|||
"io/ioutil" |
|||
) |
|||
|
|||
type Config struct { |
|||
Url string `json:"url"` |
|||
} |
|||
|
|||
var config Config |
|||
|
|||
type User struct { |
|||
Username string `json:"username"` |
|||
Password string `json:"password"` |
|||
Email string `json:"email"` |
|||
Token string `json:"token"` |
|||
} |
|||
|
|||
var users []User |
|||
|
|||
func readUsers() { |
|||
file, e := ioutil.ReadFile("users.json") |
|||
if e != nil { |
|||
fmt.Println("error:", e) |
|||
} |
|||
content := string(file) |
|||
json.Unmarshal([]byte(content), &users) |
|||
} |
|||
func readConfig() { |
|||
file, e := ioutil.ReadFile("config.json") |
|||
if e != nil { |
|||
fmt.Println("error:", e) |
|||
} |
|||
content := string(file) |
|||
json.Unmarshal([]byte(content), &config) |
|||
} |
@ -0,0 +1,89 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"encoding/json" |
|||
"fmt" |
|||
"io/ioutil" |
|||
"log" |
|||
"net/http" |
|||
"strings" |
|||
) |
|||
|
|||
type LoginResp struct { |
|||
Token string `json:"token"` |
|||
User User |
|||
} |
|||
|
|||
func signup(user User) User { |
|||
var loginResp LoginResp |
|||
url := config.Url + "/signup" |
|||
jsonStr, err := json.Marshal(user) |
|||
if err != nil { |
|||
fmt.Println(err) |
|||
} |
|||
fmt.Println(string(jsonStr)) |
|||
b := strings.NewReader(string(jsonStr)) |
|||
req, _ := http.NewRequest("POST", url, b) |
|||
req.Header.Set("Content-Type", "application/json") |
|||
res, err := http.DefaultClient.Do(req) |
|||
if err != nil { |
|||
log.Println(err) |
|||
} |
|||
defer res.Body.Close() |
|||
body, _ := ioutil.ReadAll(res.Body) |
|||
|
|||
json.Unmarshal([]byte(body), &loginResp) |
|||
|
|||
fmt.Println("token: " + loginResp.Token) |
|||
user.Token = loginResp.Token |
|||
return user |
|||
} |
|||
func login(user User) User { |
|||
var loginResp LoginResp |
|||
url := config.Url + "/login" |
|||
jsonStr, err := json.Marshal(user) |
|||
if err != nil { |
|||
fmt.Println(err) |
|||
} |
|||
fmt.Println(string(jsonStr)) |
|||
b := strings.NewReader(string(jsonStr)) |
|||
req, _ := http.NewRequest("POST", url, b) |
|||
req.Header.Set("Content-Type", "application/json") |
|||
res, err := http.DefaultClient.Do(req) |
|||
if err != nil { |
|||
log.Println(err) |
|||
} |
|||
defer res.Body.Close() |
|||
body, _ := ioutil.ReadAll(res.Body) |
|||
|
|||
json.Unmarshal([]byte(body), &loginResp) |
|||
|
|||
fmt.Println("token: " + loginResp.Token) |
|||
user.Token = loginResp.Token |
|||
return user |
|||
} |
|||
|
|||
func addTravel(user User, travel Travel) (User, Travel) { |
|||
var loginResp LoginResp |
|||
url := config.Url + "/login" |
|||
jsonStr, err := json.Marshal(user) |
|||
if err != nil { |
|||
fmt.Println(err) |
|||
} |
|||
fmt.Println(string(jsonStr)) |
|||
b := strings.NewReader(string(jsonStr)) |
|||
req, _ := http.NewRequest("POST", url, b) |
|||
req.Header.Set("Content-Type", "application/json") |
|||
res, err := http.DefaultClient.Do(req) |
|||
if err != nil { |
|||
log.Println(err) |
|||
} |
|||
defer res.Body.Close() |
|||
body, _ := ioutil.ReadAll(res.Body) |
|||
|
|||
json.Unmarshal([]byte(body), &loginResp) |
|||
|
|||
fmt.Println("token: " + loginResp.Token) |
|||
user.Token = loginResp.Token |
|||
return user |
|||
} |
@ -0,0 +1,16 @@ |
|||
[{ |
|||
"username": "u1", |
|||
"password": "u1", |
|||
"email": "u1" |
|||
}, |
|||
{ |
|||
"username": "u2", |
|||
"password": "u2", |
|||
"email": "u2" |
|||
}, |
|||
{ |
|||
"username": "u3", |
|||
"password": "u3", |
|||
"email": "u3" |
|||
} |
|||
] |