Skip to content

Commit

Permalink
sun-api & sun-ui. added privacy fields
Browse files Browse the repository at this point in the history
  • Loading branch information
edospadoni committed Jun 11, 2024
1 parent 1454e60 commit c61c86a
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 20 deletions.
8 changes: 7 additions & 1 deletion deploy/ansible/roles/icarodb/files/icaro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ CREATE TABLE `accounts` (
`username` varchar (200) NOT NULL,
`password` varchar (200) NOT NULL,
`email` varchar(250),
`privacy_name` varchar(512),
`privacy_vat` varchar(512),
`privacy_address` varchar(512),
`privacy_email` varchar(512),
`privacy_dpo` varchar(512),
`privacy_dpo_mail` varchar(512),
`created` datetime,
UNIQUE KEY (`username`),
UNIQUE KEY (`uuid`),
Expand All @@ -17,7 +23,7 @@ CREATE TABLE `accounts` (
);

/* CREATE DEFAULT ADMIN USER */
INSERT INTO `accounts` VALUES (1, 0, "", "admin", "Admin", "admin", MD5("admin"), "", NOW());
INSERT INTO `accounts` VALUES (1, 0, "", "admin", "Admin", "admin", MD5("admin"), "", "", "", "", "", "", "", NOW());

CREATE TABLE `account_preferences` (
`id` serial,
Expand Down
38 changes: 30 additions & 8 deletions sun/sun-api/methods/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,20 @@ func CreateAccount(c *gin.Context) {
passwordHash := fmt.Sprintf("%x", h.Sum(nil))

account := models.Account{
CreatorId: creatorId,
Uuid: json.Uuid,
Type: json.Type,
Name: json.Name,
Username: json.Username,
Password: passwordHash,
Email: json.Email,
Created: time.Now().UTC(),
CreatorId: creatorId,
Uuid: json.Uuid,
Type: json.Type,
Name: json.Name,
Username: json.Username,
Password: passwordHash,
Email: json.Email,
PrivacyName: "",
PrivacyVAT: "",
PrivacyAddress: "",
PrivacyEmail: "",
PrivacyDPO: "",
PrivacyDPOMail: "",
Created: time.Now().UTC(),
}

// create account record
Expand Down Expand Up @@ -182,6 +188,22 @@ func UpdateAccount(c *gin.Context) {
account.Type = json.Type
}

// privacy update
if len(json.PrivacyName) > 0 {
account.PrivacyName = json.PrivacyName
}
if len(json.PrivacyVAT) > 0 {
account.PrivacyVAT = json.PrivacyVAT
}
if len(json.PrivacyAddress) > 0 {
account.PrivacyAddress = json.PrivacyAddress
}
if len(json.PrivacyEmail) > 0 {
account.PrivacyEmail = json.PrivacyEmail
}
account.PrivacyDPO = json.PrivacyDPO
account.PrivacyDPOMail = json.PrivacyDPOMail

// NOTE: Subscription plan change is not supported

db.Save(&account)
Expand Down
30 changes: 21 additions & 9 deletions sun/sun-api/models/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ package models
import "time"

type Account struct {
Id int `db:"id" json:"id"`
CreatorId int `db:"creator_id" json:"creator_id"`
Uuid string `db:"uuid" json:"uuid"`
Type string `db:"type" json:"type"`
Name string `db:"name" json:"name"`
Username string `db:"username" json:"username"`
Password string `db:"password" json:"-"`
Email string `db:"email" json:"email"`
Created time.Time `db:"created" json:"created"`
Id int `db:"id" json:"id"`
CreatorId int `db:"creator_id" json:"creator_id"`
Uuid string `db:"uuid" json:"uuid"`
Type string `db:"type" json:"type"`
Name string `db:"name" json:"name"`
Username string `db:"username" json:"username"`
Password string `db:"password" json:"-"`
Email string `db:"email" json:"email"`
PrivacyName string `db:"privacy_name" json:"privacy_name"`
PrivacyVAT string `db:"privacy_vat" json:"privacy_vat"`
PrivacyAddress string `db:"privacy_address" json:"privacy_address"`
PrivacyEmail string `db:"privacy_email" json:"privacy_email"`
PrivacyDPO string `db:"privacy_dpo" json:"privacy_dpo"`
PrivacyDPOMail string `db:"privacy_dpo_mail" json:"privacy_dpo_mail"`
Created time.Time `db:"created" json:"created"`
}

type AccountJSON struct {
Expand All @@ -45,6 +51,12 @@ type AccountJSON struct {
Username string `json:"username"`
Password string `json:"password"`
Email string `json:"email"`
PrivacyName string `json:"privacy_name"`
PrivacyVAT string `json:"privacy_vat"`
PrivacyAddress string `json:"privacy_address"`
PrivacyEmail string `json:"privacy_email"`
PrivacyDPO string `json:"privacy_dpo"`
PrivacyDPOMail string `json:"privacy_dpo_mail"`
Created time.Time `json:"created"`
HotspotId int `json:"hotspot_id"`
HotspotName string `json:"hotspot_name"`
Expand Down
88 changes: 87 additions & 1 deletion sun/sun-ui/src/components/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,69 @@
</div>
</div>
</div>

<!-- privacy fields -->
<div v-if="user.info.type == 'reseller'" class="col-xs-12 col-sm-12 col-md-6">
<div class="card-pf card-pf-accented">
<div class="card-pf-heading">
<h2 class="card-pf-title">
{{ $t("profile.privacy_fields") }}
<div v-if="!privacy.isLoading" class="fa fa-lock card-info-title right"></div>
<div v-if="privacy.isLoading" class="spinner spinner-sm right"></div>
</h2>
</div>
<form v-if="!privacy.isLoading" class="form-horizontal" role="form" v-on:submit.prevent="updatePrivacyFields()">
<div class="card-pf-body">
<div class="form-group">
<label class="col-sm-4 control-label">{{ $t("profile.privacy_name") }}</label>
<div class="col-sm-8">
<input v-model="user.info.privacy_name" required type="text" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">{{ $t("profile.privacy_vat") }}</label>
<div class="col-sm-8">
<input v-model="user.info.privacy_vat" required type="number" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">{{ $t("profile.privacy_address") }}</label>
<div class="col-sm-8">
<input v-model="user.info.privacy_address" required type="text" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">{{ $t("profile.privacy_email") }}</label>
<div class="col-sm-8">
<input v-model="user.info.privacy_email" required type="email" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">{{ $t("profile.privacy_dpo") }}</label>
<div class="col-sm-8">
<input v-model="user.info.privacy_dpo" type="text" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">{{ $t("profile.privacy_dpo_mail") }}</label>
<div class="col-sm-8">
<input v-model="user.info.privacy_dpo_mail" type="email" class="form-control">
</div>
</div>
</div>
<div class="card-pf-footer">
<div class="dropdown card-pf-time-frame-filter">
<button type="submit" class="btn btn-default">{{ $t("update") }}</button>
</div>
<p>
<a href="#" class="card-pf-link-with-icon">
</a>
</p>
</div>
</form>
</div>
</div>

<!-- SMS warning threshold -->
<div class="col-xs-12 col-sm-12 col-md-6">
<div class="card-pf card-pf-accented">
Expand Down Expand Up @@ -72,6 +135,7 @@
</div>
</div>
</div>

<!-- disclaimer -->
<div
v-if="disclaimers.data && disclaimers.data.length"
Expand Down Expand Up @@ -179,10 +243,11 @@ import UtilService from "../services/util";
import StatsService from "../services/stats";
import DisclaimerService from "../services/disclaimer";
import PreferenceService from "../services/preference";
import AccountService from '../services/account';
export default {
name: "Profile",
mixins: [LoginService, StorageService, UtilService, StatsService, DisclaimerService, PreferenceService],
mixins: [LoginService, StorageService, UtilService, StatsService, DisclaimerService, PreferenceService, AccountService],
data() {
return {
msg: this.$i18n.t("menu.profile"),
Expand All @@ -200,6 +265,9 @@ export default {
isLoading: true,
data: {}
},
privacy: {
isLoading: false,
},
disclaimers: {
data: {},
isLoading: true,
Expand Down Expand Up @@ -337,6 +405,24 @@ export default {
}, 2000);
}
);
},
updatePrivacyFields() {
this.privacy.isLoading = true;
this.accountModify(this.user.login.id, {
privacy_name: this.user.info.privacy_name,
privacy_vat: this.user.info.privacy_vat,
privacy_address: this.user.info.privacy_address,
privacy_email: this.user.info.privacy_email,
privacy_dpo: this.user.info.privacy_dpo,
privacy_dpo_mail: this.user.info.privacy_dpo_mail,
},
success => {
this.privacy.isLoading = false;
},
error => {
this.privacy.isLoading = false;
console.error(error.body.message);
});
}
}
};
Expand Down
9 changes: 8 additions & 1 deletion sun/sun-ui/src/i18n/locale-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@
"default_disclaimer": "Default disclaimers",
"privacy_disclaimer": "Privacy disclaimer",
"tos_disclaimer": "Terms of use disclaimer",
"default": "Default"
"default": "Default",
"privacy_fields": "Privacy fields",
"privacy_name": "Reseller's business name",
"privacy_vat": "Reseller's business VAT",
"privacy_address": "Reseller's business address",
"privacy_email": "Reseller's business email",
"privacy_dpo": "Reseller's business DPO (optional)",
"privacy_dpo_mail": "Reseller's business DPO email (optional)"
},
"hotspot": {
"yes": "Yes",
Expand Down

0 comments on commit c61c86a

Please sign in to comment.