<div *ngIf="formErrors.fromEmail" class="form-error">{{ formErrors.fromEmail }}</div>
</div>
+ <div class="form-group">
+ <label i18n for="subject">Subject</label>
+ <input
+ type="text" id="subject"
+ formControlName="subject" [ngClass]="{ 'input-error': formErrors['subject'] }"
+ >
+ <div *ngIf="formErrors.subject" class="form-error">{{ formErrors.subject }}</div>
+ </div>
+
<div class="form-group">
<label i18n for="body">Your message</label>
<textarea id="body" formControlName="body" [ngClass]="{ 'input-error': formErrors['body'] }">
this.buildForm({
fromName: this.instanceValidatorsService.FROM_NAME,
fromEmail: this.instanceValidatorsService.FROM_EMAIL,
+ subject: this.instanceValidatorsService.SUBJECT,
body: this.instanceValidatorsService.BODY
})
}
sendForm () {
const fromName = this.form.value['fromName']
const fromEmail = this.form.value[ 'fromEmail' ]
+ const subject = this.form.value[ 'subject' ]
const body = this.form.value[ 'body' ]
- this.instanceService.contactAdministrator(fromEmail, fromName, body)
+ this.instanceService.contactAdministrator(fromEmail, fromName, subject, body)
.subscribe(
() => {
this.notifier.success(this.i18n('Your message has been sent.'))
export class InstanceValidatorsService {
readonly FROM_EMAIL: BuildFormValidator
readonly FROM_NAME: BuildFormValidator
+ readonly SUBJECT: BuildFormValidator
readonly BODY: BuildFormValidator
constructor (private i18n: I18n) {
}
}
+ this.SUBJECT = {
+ VALIDATORS: [
+ Validators.required,
+ Validators.minLength(1),
+ Validators.maxLength(120)
+ ],
+ MESSAGES: {
+ 'required': this.i18n('A subject is required.'),
+ 'minlength': this.i18n('The subject must be at least 1 character long.'),
+ 'maxlength': this.i18n('The subject cannot be more than 120 characters long.')
+ }
+ }
+
this.BODY = {
VALIDATORS: [
Validators.required,
.pipe(catchError(res => this.restExtractor.handleError(res)))
}
- contactAdministrator (fromEmail: string, fromName: string, message: string) {
+ contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) {
const body = {
fromEmail,
fromName,
+ subject,
body: message
}
async function contactAdministrator (req: express.Request, res: express.Response) {
const data = req.body as ContactForm
- await Emailer.Instance.addContactFormJob(data.fromEmail, data.fromName, data.body)
+ await Emailer.Instance.addContactFormJob(data.fromEmail, data.fromName, data.subject, data.body)
await Redis.Instance.setContactFormIp(req.ip)
return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
}
- addContactFormJob (fromEmail: string, fromName: string, body: string) {
+ addContactFormJob (fromEmail: string, fromName: string, subject: string, body: string) {
const text = 'Hello dear admin,\n\n' +
fromName + ' sent you a message' +
'\n\n---------------------------------------\n\n' +
fromDisplayName: fromEmail,
replyTo: fromEmail,
to: [ CONFIG.ADMIN.EMAIL ],
- subject: CONFIG.EMAIL.OBJECT.PREFIX + 'Contact form submitted',
+ subject: CONFIG.EMAIL.OBJECT.PREFIX + subject,
text
}
const defaultBody = {
fromName: 'super name',
fromEmail: 'toto@example.com',
+ subject: 'my subject',
body: 'Hello, how are you?'
}
let emailPort: number
url: server.url,
fromEmail: 'toto@example.com',
body: 'my super message',
+ subject: 'my subject',
fromName: 'Super toto'
})
expect(email['from'][0]['address']).equal('test-admin@localhost')
expect(email['from'][0]['name']).equal('toto@example.com')
expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
- expect(email['subject']).contains('Contact form')
+ expect(email['subject']).contains('my subject')
expect(email['text']).contains('my super message')
})
url: server.url,
fromEmail: 'toto@example.com',
body: 'my super message',
+ subject: 'my subject',
fromName: 'Super toto'
})
fromEmail: 'toto@example.com',
body: 'my super message',
fromName: 'Super toto',
+ subject: 'my subject',
expectedStatus: 403
})
})
await sendContactForm({
url: server.url,
fromEmail: 'toto@example.com',
- body: 'my super message',
- fromName: 'Super toto'
+ fromName: 'Super toto',
+ subject: 'my subject',
+ body: 'my super message'
})
})
url: string,
fromEmail: string,
fromName: string,
+ subject: string,
body: string,
expectedStatus?: number
}) {
const body: ContactForm = {
fromEmail: options.fromEmail,
fromName: options.fromName,
+ subject: options.subject,
body: options.body
}
return request(options.url)
export interface ContactForm {
fromEmail: string
fromName: string
+ subject: string
body: string
}