Open platform to collect and prioritize feedback
use md5 on server side (#61)
Guilherme Oenning399842d27a1d
diff --git a/app/models/identity.go b/app/models/identity.goindex fd0e1e72d..3b03fa4b3 100644--- a/app/models/identity.go+++ b/app/models/identity.go@@ -14,7 +14,8 @@ type Tenant struct {type User struct {ID int `json:"id"`Name string `json:"name"`- Email string `json:"email"`+ Email string `json:"-"`+ Gravatar string `json:"gravatar"`Tenant *Tenant `json:"-"`Role int `json:"role"`Providers []*UserProvider `json:"-"`diff --git a/app/storage/postgres/user.go b/app/storage/postgres/user.goindex 9d7e6aafb..a2e9ea893 100644--- a/app/storage/postgres/user.go+++ b/app/storage/postgres/user.go@@ -1,10 +1,13 @@package postgresimport (+ "crypto/md5""time""database/sql"+ "fmt"+"github.com/getfider/fider/app""github.com/getfider/fider/app/models""github.com/getfider/fider/app/pkg/dbx"@@ -29,6 +32,7 @@ func (u *dbUser) toModel() *models.User {ID: int(u.ID.Int64),Name: u.Name.String,Email: u.Email.String,+ Gravatar: fmt.Sprintf("%x", md5.Sum([]byte(u.Email.String))),Tenant: u.Tenant.toModel(),Role: int(u.Role.Int64),Providers: make([]*models.UserProvider, len(u.Providers)),diff --git a/public/components/ShowIdeaResponse.tsx b/public/components/ShowIdeaResponse.tsxindex 3c6aecec9..1dccd31e1 100644--- a/public/components/ShowIdeaResponse.tsx+++ b/public/components/ShowIdeaResponse.tsx@@ -15,7 +15,7 @@ export const ShowIdeaResponse = (props: IdeaResponseProps): JSX.Element => {return <div className="fdr-response item ui raised segment"><span className={`ui ribbon label ${status.color}`}>{ status.title }</span><div className="info">- <Gravatar email={props.response.user.email}/> <u>{props.response.user.name}</u>+ <Gravatar hash={props.response.user.gravatar}/> <u>{props.response.user.name}</u><span title={props.response.respondedOn.toString()}>{ moment(props.response.respondedOn).fromNow() }</span>diff --git a/public/components/common/Gravatar.tsx b/public/components/common/Gravatar.tsxindex 7d799769a..c6dda9ff1 100644--- a/public/components/common/Gravatar.tsx+++ b/public/components/common/Gravatar.tsx@@ -1,7 +1,12 @@import * as React from 'react';import md5 = require('md5');-export const Gravatar = (props: {email?: string}) => {- const hash = props.email ? md5(props.email) : '';+interface GravatarProps {+ hash?: string;+ email?: string;+}++export const Gravatar = (props: GravatarProps) => {+ const hash = props.email ? md5(props.email) : props.hash || '';return <img className="ui avatar image" src={ 'https://www.gravatar.com/avatar/' + hash } />;-};\ No newline at end of file+};diff --git a/public/components/common/Header.tsx b/public/components/common/Header.tsxindex 4a6f6dab0..6e2700884 100644--- a/public/components/common/Header.tsx+++ b/public/components/common/Header.tsx@@ -33,9 +33,6 @@ export class Header extends React.Component<{}, {}> {public render() {const items = this.user ?<div className="ui divided list">- <div className="item">- <b>{ this.user.email }</b>- </div>{this.session.isStaff() &&<div className="item">@@ -60,7 +57,7 @@ export class Header extends React.Component<{}, {}> {{ this.tenant.name }</a><a ref={(e) => { this.dropdown = e!; } } className="item right signin">- <Gravatar email={this.user.email} />+ <Gravatar hash={this.user.gravatar} />{ this.user.name || 'Sign in' }<i className="dropdown icon"></i></a>diff --git a/public/models/identity.ts b/public/models/identity.tsindex ac38d158b..70c6ce742 100644--- a/public/models/identity.ts+++ b/public/models/identity.ts@@ -7,6 +7,6 @@ export interface Tenant {export interface User {id: number;name: string;- email: string;+ gravatar: string;role: number;}diff --git a/public/pages/ShowIdeaPage.tsx b/public/pages/ShowIdeaPage.tsxindex 6b8c0142d..0785e51e2 100644--- a/public/pages/ShowIdeaPage.tsx+++ b/public/pages/ShowIdeaPage.tsx@@ -36,7 +36,7 @@ export class ShowIdeaPage extends React.Component<{}, {}> {const commentsList = this.comments.length ? this.comments.map((c) =><div className="comment"><a className="avatar">- <Gravatar email={c.user.email} />+ <Gravatar hash={c.user.gravatar} /></a><div className="content"><span className="author">{ c.user.name }</span>@@ -67,7 +67,7 @@ export class ShowIdeaPage extends React.Component<{}, {}> {<p>#{ this.idea.number } shared by - <Gravatar email={this.idea.user.email}/> <u>{this.idea.user.name}</u> + <Gravatar hash={this.idea.user.gravatar}/> <u>{this.idea.user.name}</u> <span title={this.idea.createdOn}>{ moment(this.idea.createdOn).fromNow() }</span></p></div>diff --git a/public/pages/SiteHomePage.tsx b/public/pages/SiteHomePage.tsxindex 514bb0417..b093a7267 100644--- a/public/pages/SiteHomePage.tsx+++ b/public/pages/SiteHomePage.tsx@@ -34,7 +34,7 @@ export class SiteHomePage extends React.Component<{}, {}> {<MultiLineText text={ x.description } /></div><div className="extra">- #{ x.number } shared by <Gravatar email={x.user.email}/> <u>{x.user.name}</u>+ #{ x.number } shared by <Gravatar hash={x.user.gravatar}/> <u>{x.user.name}</u><span title={x.createdOn}>{ moment(x.createdOn).fromNow() }</span></div><ShowIdeaResponse status={ x.status } response={ x.response } />