public function edit($id) { if (Input::exist()) { $data = Input::parse(); $contact = Contact::find($id); $contact->update($data); echo json_encode($contact); } }
function changePassword() { $input = Input::parse(); if (Token::check($input['token'])) { $validate = new Validate(); $validate->check($input, array('password_current' => ['required' => true, 'min' => 6], 'password' => ['required' => true, 'min' => 6], 'password_repeat' => ['required' => true, 'min' => 6, 'matches' => 'password'])); if ($validate->passed()) { $user = new User(); if (Hash::make($input['password_current'], config::get('encryption/salt')) !== $user->data()->password) { echo "incorrent password"; } else { $user->update(array('password' => Hash::make($input['password'], config::get('ecryption/salt')))); Session::flash('success', 'Successfully changed password'); Redirect::to('changepassword'); } } else { Session::flash('error', $validate->errors()); Redirect::to('changepassword'); } } }
function signup() { $input = Input::parse(); if (Token::check($input['token'])) { $validate = new Validate(); $validate->check($input, array('username' => ['required' => true, 'min' => 5, 'max' => 20, 'unique' => 'users'], 'name' => ['required' => true, 'max' => 50], 'password' => ['required' => true, 'min' => 6])); if ($validate->passed()) { $user = new User(); $salt = config::get("encription/hash"); try { $user->create(array('username' => $input['username'], 'password' => Hash::make($input['password']), 'name' => $input['name'], 'joined' => date('Y-m-d H:i:s'), 'group_id' => 1)); } catch (Exception $e) { die($e->getMessage()); } Session::flash('login', 'You registered successfully! Please login!'); Redirect::to('login'); } else { Session::flash('error', $validate->errors()); Redirect::to('signup'); } } else { echo "Invalid token"; } }