email and password action/redusers work

This commit is contained in:
Toni Dezman 2017-08-26 14:07:31 +02:00
parent eb0641d76a
commit ea9a195f09
5 changed files with 60 additions and 7 deletions

View file

@ -12,6 +12,24 @@ module ClientApi
end
end
def change_password
binding.pry
end
def change_email
user = current_user
user.email = params['email']
saved_email = if user.save
user.email
else
user.reload.email
end
respond_to do |format|
format.json { render json: { email: saved_email } }
end
end
def change_full_name
user = current_user
user.name = params['fullName']

View file

@ -25,6 +25,8 @@ export const RECENT_NOTIFICATIONS_PATH = "/client_api/recent_notifications";
export const CURRENT_USER_PATH = "/client_api/current_user_info";
export const CHANGE_USER_FULL_NAME_PATH = "/client_api/user/change_full_name";
export const CHANGE_USER_INITIALS_PATH = "/client_api/user/change_initials";
export const CHANGE_USER_EMAIL_PATH = "/client_api/user/change_email";
export const CHANGE_USER_PASSWORD_PATH = "/client_api/user/change_password";
// info dropdown_title
export const CUSTOMER_SUPPORT_LINK = "http://scinote.net/support";

View file

@ -3,7 +3,9 @@ import axios from "../../app/axios";
import {
CHANGE_USER_FULL_NAME_PATH,
CURRENT_USER_PATH,
CHANGE_USER_INITIALS_PATH
CHANGE_USER_INITIALS_PATH,
CHANGE_USER_EMAIL_PATH,
CHANGE_USER_PASSWORD_PATH
} from "../../app/routes";
import {
@ -41,7 +43,7 @@ export function getCurrentUser() {
};
}
export function savedChangedFullName({ fullName }) {
export function saveFullName({ fullName }) {
return {
type: CHANGE_CURRENT_USER_FULL_NAME,
payload: fullName
@ -56,13 +58,13 @@ export function changeFullName(name) {
fullName: name
})
.then(({ data }) => {
dispatch(savedChangedFullName(data));
dispatch(saveFullName(data));
})
.catch(err => console.log(err));
};
}
export function savedChangeInitials({ initials }) {
export function saveInitials({ initials }) {
return {
type: CHANGE_CURRENT_USER_INITIALS,
payload: initials
@ -77,26 +79,54 @@ export function changeInitials(initials) {
initials
})
.then(({ data }) => {
dispatch(savedChangeInitials(data));
dispatch(saveInitials(data));
})
.catch(err => console.log(err));
};
}
export function changeEmail(email) {
export function saveEmail({ email }) {
return {
type: CHANGE_CURRENT_USER_EMAIL,
payload: email
};
}
export function changePassword(password) {
export function changeEmail(email) {
return dispatch => {
axios
.post(CHANGE_USER_EMAIL_PATH, {
withCredentials: true,
email
})
.then(({ data }) => {
dispatch(saveEmail(data));
})
.catch(err => console.log(err));
};
}
export function savePassword(password) {
return {
type: CHANGE_CURRENT_USER_PASSWORD,
payload: password
};
}
export function changePassword(passwrd) {
return dispatch => {
axios
.post(CHANGE_USER_PASSWORD_PATH, {
withCredentials: true,
passwrd
})
.then(({ data }) => {
dispatch(savePassword(data));
})
.catch(err => console.log(err));
};
}
export function changeAvatar(avatarSrc) {
return {
type: CHANGE_CURRENT_USER_AVATAR,

View file

@ -98,6 +98,7 @@ class InputEnabled extends Component {
<FormControl
type={this.props.inputType}
value={this.state.value}
onChange={this.handleChange}
onKeyPress={this.handleKeyPress}
autoFocus
/>

View file

@ -27,6 +27,8 @@ Rails.application.routes.draw do
get '/current_user_info', to: 'users/users#current_user_info'
post '/user/change_full_name', to: 'users/users#change_full_name'
post '/user/change_initials', to: 'users/users#change_initials'
post '/user/change_email', to: 'users/users#change_email'
post '/user/change_password', to: 'users/users#change_password'
end
# Save sample table state