summaryrefslogtreecommitdiff
path: root/hscript/user.hh
blob: dfda46d7b6cab5eb140392e46e2e9938cdd9b1bd (plain) (blame)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * user.hh - Definition of the Key classes for user account data
 * libhscript, the HorizonScript library for
 * Project Horizon
 *
 * Copyright (c) 2019-2020 Adélie Linux and contributors.  All rights reserved.
 * This code is licensed under the AGPL 3.0 license, as noted in the
 * LICENSE-code file in the root directory of this repository.
 *
 * SPDX-License-Identifier: AGPL-3.0-only
 */

#ifndef __HSCRIPT_USER_HH_
#define __HSCRIPT_USER_HH_

#include <set>
#include <string>
#include "key.hh"

namespace Horizon {
namespace Keys {

class RootPassphrase : public StringKey {
private:
    RootPassphrase(const Script *_s, const ScriptLocation &_p,
                   const std::string &my_pw) : StringKey(_s, _p, my_pw) {}
public:
    static Key *parseFromData(const std::string &, const ScriptLocation &,
                              int*, int*, const Script *);
    bool validate() const override;
    bool execute() const override;
};

class Username : public StringKey {
private:
    Username(const Script *_s, const ScriptLocation &_p,
             const std::string &name) : StringKey(_s, _p, name) {}
public:
    static Key *parseFromData(const std::string &, const ScriptLocation &,
                              int*, int*, const Script *);
    bool execute() const override;
};

class UserAlias : public Key {
private:
    const std::string _username;
    const std::string _alias;

    UserAlias(const Script *_s, const ScriptLocation &_p, const std::string &_n,
              const std::string &_a) : Key(_s, _p), _username(_n), _alias(_a) {}
public:
    static Key *parseFromData(const std::string &, const ScriptLocation &,
                              int*, int*, const Script *);

    /*! Retrieve the username for this alias. */
    const std::string &username() const { return this->_username; }
    /*! Retrieve the alias for the account. */
    const std::string &alias() const { return this->_alias; }

    bool validate() const override;
    bool execute() const override;
};

class UserPassphrase : public Key {
private:
    const std::string _username;
    const std::string _passphrase;

    UserPassphrase(const Script *_s, const ScriptLocation &_pos,
                   const std::string &_n, const std::string &_p) :
        Key(_s, _pos), _username(_n), _passphrase(_p) {}
public:
    static Key *parseFromData(const std::string &, const ScriptLocation &,
                              int*, int*, const Script *);

    /*! Retrieve the username for this passphrase. */
    const std::string &username() const { return this->_username; }
    /*! Retrieve the passphrase for the account. */
    const std::string &passphrase() const { return this->_passphrase; }

    bool validate() const override;
    bool execute() const override;
};

class UserIcon : public Key {
private:
    const std::string _username;
    const std::string _icon_path;

    UserIcon(const Script *_s, const ScriptLocation &_p, const std::string &_n,
             const std::string &_i) :
        Key(_s, _p), _username(_n), _icon_path(_i) {}
public:
    static Key *parseFromData(const std::string &, const ScriptLocation &,
                              int*, int*, const Script *);

    /*! Retrieve the username for this icon. */
    const std::string &username() const { return this->_username; }
    /*! Retrieve the icon path for the account. */
    const std::string &icon() const { return this->_icon_path; }

    bool validate() const override;
    bool execute() const override;
};

class UserGroups : public Key {
private:
    const std::string _username;
    const std::set<std::string> _groups;

    UserGroups(const Script *_s, const ScriptLocation &_pos,
               const std::string &_n, const std::set<std::string> &_g) :
        Key(_s, _pos), _username(_n), _groups(_g) {}
public:
    static Key *parseFromData(const std::string &, const ScriptLocation &,
                              int*, int*, const Script *);

    /*! Retrieve the username for this group set. */
    const std::string &username() const { return this->_username; }
    /*! Retrieve the groups for the account. */
    const std::set<std::string> &groups() const { return this->_groups; }

    bool validate() const override;
    bool execute() const override;
};

}
}

#endif /* !__HSCRIPT_USER_HH_ */