summaryrefslogtreecommitdiff
path: root/front-end/src/service/user-service.jsx
blob: 04f2b568184b9092f6462e41265e6877301c909c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import PGUtil    from 'util/util.jsx'
import PGConstant from 'util/constant.jsx'

const _util       = new PGUtil();

class User{
    farmerApply(farmerInfo){
        let url = PGConstant.base_url + '/my-machine/';
        return _util.request({
            type: 'post',
            url: url,
            data: farmerInfo
        });
    }

    login(loginInfo){
        let url = PGConstant.base_url + '/login/';
        return _util.request({
            type: 'post',
            url: url,
            data: loginInfo
        });
    }
    // check if the loginInfo is legel
    checkLoginInfo(loginInfo){
        let username = $.trim(loginInfo.username),
            password = $.trim(loginInfo.password);
        // check username
        if(typeof username !== 'string' || username.length ===0){
            return {
                status: false,
                msg: 'username cannot be an empty string!'
            }
        }
        // check password
        if(typeof password !== 'string' || password.length ===0){
            return {
                status: false,
                msg: 'password cannot be an empty string!!'
            }
        }
        return {
            status : true,
            msg : 'justify pass'
        }
    }
    // logout
    logout(){
        // let url = PGConstant.base_url + '/logout';
        // return _util.request({
        //     type    : 'post',
        //     url     : url
        // });
        return true;
    }

    getUserMachineManageList(listParam){
        let url = PGConstant.base_url + '/my-machine';
        return _util.request({
            type    : 'get',
            url     : url,
            data    : listParam
        //     listParam.page = page;
        //     listParam.username = this.state.username;
        });
    }

    getUserPortalInfo(username=''){
        let url = PGConstant.base_url + '/user-portal/' + username;
        return _util.request({
            type    : 'get',
            url     : url,
            data    : {}
        });
    }

}

export default User;