summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docker-compose.yml2
-rwxr-xr-xinstall.sh2
-rw-r--r--server/src/actions/user.rs8
-rw-r--r--server/src/apub.rs2
-rw-r--r--server/src/lib.rs8
-rw-r--r--server/src/websocket_server/server.rs4
-rw-r--r--ui/src/components/communities.tsx1
-rw-r--r--ui/src/components/community.tsx1
-rw-r--r--ui/src/components/inbox.tsx1
-rw-r--r--ui/src/components/main.tsx1
-rw-r--r--ui/src/components/modlog.tsx1
-rw-r--r--ui/src/components/navbar.tsx4
-rw-r--r--ui/src/components/search.tsx1
-rw-r--r--ui/src/components/user.tsx1
14 files changed, 27 insertions, 10 deletions
diff --git a/docker-compose.yml b/docker-compose.yml
index 03c72881..1f86c531 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -22,6 +22,8 @@ services:
environment:
LEMMY_FRONT_END_DIR: /app/dist
DATABASE_URL: postgres://rrr:rrr@db:5432/rrr
+ JWT_SECRET: changeme
+ HOSTNAME: rrr
restart: always
depends_on:
db:
diff --git a/install.sh b/install.sh
index 071acc6f..80d3277a 100755
--- a/install.sh
+++ b/install.sh
@@ -2,6 +2,8 @@
set -e
export DATABASE_URL=postgres://rrr:rrr@localhost/rrr
+export JWT_SECRET=changeme
+export HOSTNAME=rrr
cd ui
yarn
diff --git a/server/src/actions/user.rs b/server/src/actions/user.rs
index 58cfd89d..9c9e0a52 100644
--- a/server/src/actions/user.rs
+++ b/server/src/actions/user.rs
@@ -3,7 +3,7 @@ use diesel::*;
use diesel::result::Error;
use schema::user_::dsl::*;
use serde::{Serialize, Deserialize};
-use {Crud,is_email_regex};
+use {Crud,is_email_regex, Settings};
use jsonwebtoken::{encode, decode, Header, Validation, TokenData};
use bcrypt::{DEFAULT_COST, hash};
@@ -86,7 +86,7 @@ impl Claims {
validate_exp: false,
..Validation::default()
};
- decode::<Claims>(&jwt, "secret".as_ref(), &v)
+ decode::<Claims>(&jwt, Settings::get().jwt_secret.as_ref(), &v)
}
}
@@ -96,9 +96,9 @@ impl User_ {
let my_claims = Claims {
id: self.id,
username: self.name.to_owned(),
- iss: "rrf".to_string() // TODO this should come from config file
+ iss: self.fedi_name.to_owned(),
};
- encode(&Header::default(), &my_claims, "secret".as_ref()).unwrap()
+ encode(&Header::default(), &my_claims, Settings::get().jwt_secret.as_ref()).unwrap()
}
pub fn find_by_email_or_username(conn: &PgConnection, username_or_email: &str) -> Result<Self, Error> {
diff --git a/server/src/apub.rs b/server/src/apub.rs
index a9a417e2..4fc0ba33 100644
--- a/server/src/apub.rs
+++ b/server/src/apub.rs
@@ -50,7 +50,7 @@ mod tests {
};
let person = expected_user.person();
- assert_eq!("http://0.0.0.0/api/v1/user/thom", person.object_props.id_string().unwrap());
+ assert_eq!("rrr/api/v1/user/thom", person.object_props.id_string().unwrap());
let json = serde_json::to_string_pretty(&person).unwrap();
println!("{}", json);
diff --git a/server/src/lib.rs b/server/src/lib.rs
index d8d7f152..71b72ac3 100644
--- a/server/src/lib.rs
+++ b/server/src/lib.rs
@@ -75,7 +75,8 @@ pub fn establish_connection() -> PgConnection {
pub struct Settings {
db_url: String,
- hostname: String
+ hostname: String,
+ jwt_secret: String,
}
impl Settings {
@@ -84,7 +85,8 @@ impl Settings {
Settings {
db_url: env::var("DATABASE_URL")
.expect("DATABASE_URL must be set"),
- hostname: env::var("HOSTNAME").unwrap_or("http://0.0.0.0".to_string())
+ hostname: env::var("HOSTNAME").unwrap_or("rrr".to_string()),
+ jwt_secret: env::var("JWT_SECRET").unwrap_or("changeme".to_string()),
}
}
fn api_endpoint(&self) -> String {
@@ -143,7 +145,7 @@ mod tests {
use {Settings, is_email_regex, remove_slurs, has_slurs, fuzzy_search};
#[test]
fn test_api() {
- assert_eq!(Settings::get().api_endpoint(), "http://0.0.0.0/api/v1");
+ assert_eq!(Settings::get().api_endpoint(), "rrr/api/v1");
}
#[test] fn test_email() {
diff --git a/server/src/websocket_server/server.rs b/server/src/websocket_server/server.rs
index aaeae132..82c4007d 100644
--- a/server/src/websocket_server/server.rs
+++ b/server/src/websocket_server/server.rs
@@ -13,7 +13,7 @@ use diesel::PgConnection;
use failure::Error;
use std::time::{SystemTime};
-use {Crud, Joinable, Likeable, Followable, Bannable, Saveable, establish_connection, naive_now, naive_from_unix, SortType, SearchType, has_slurs, remove_slurs};
+use {Crud, Joinable, Likeable, Followable, Bannable, Saveable, establish_connection, naive_now, naive_from_unix, SortType, SearchType, has_slurs, remove_slurs, Settings};
use actions::community::*;
use actions::user::*;
use actions::post::*;
@@ -902,7 +902,7 @@ impl Perform for Register {
// Register the new user
let user_form = UserForm {
name: self.username.to_owned(),
- fedi_name: "rrf".into(),
+ fedi_name: Settings::get().hostname.into(),
email: self.email.to_owned(),
password_encrypted: self.password.to_owned(),
preferred_username: None,
diff --git a/ui/src/components/communities.tsx b/ui/src/components/communities.tsx
index 190f8e3d..96864e9a 100644
--- a/ui/src/components/communities.tsx
+++ b/ui/src/components/communities.tsx
@@ -174,6 +174,7 @@ export class Communities extends Component<any, CommunitiesState> {
this.state.communities = res.communities;
this.state.communities.sort((a, b) => b.number_of_subscribers - a.number_of_subscribers);
this.state.loading = false;
+ window.scrollTo(0,0);
this.setState(this.state);
} else if (op == UserOperation.FollowCommunity) {
let res: CommunityResponse = msg;
diff --git a/ui/src/components/community.tsx b/ui/src/components/community.tsx
index 93cdbd92..28841a2e 100644
--- a/ui/src/components/community.tsx
+++ b/ui/src/components/community.tsx
@@ -215,6 +215,7 @@ export class Community extends Component<any, State> {
let res: GetPostsResponse = msg;
this.state.posts = res.posts;
this.state.loading = false;
+ window.scrollTo(0,0);
this.setState(this.state);
} else if (op == UserOperation.CreatePostLike) {
let res: CreatePostLikeResponse = msg;
diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx
index 659a4a20..69ddc44b 100644
--- a/ui/src/components/inbox.tsx
+++ b/ui/src/components/inbox.tsx
@@ -170,6 +170,7 @@ export class Inbox extends Component<any, InboxState> {
let res: GetRepliesResponse = msg;
this.state.replies = res.replies;
this.sendRepliesCount();
+ window.scrollTo(0,0);
this.setState(this.state);
} else if (op == UserOperation.EditComment) {
let res: CommentResponse = msg;
diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx
index cd679ecb..1ec016ea 100644
--- a/ui/src/components/main.tsx
+++ b/ui/src/components/main.tsx
@@ -383,6 +383,7 @@ export class Main extends Component<any, MainState> {
let res: GetPostsResponse = msg;
this.state.posts = res.posts;
this.state.loading = false;
+ window.scrollTo(0,0);
this.setState(this.state);
} else if (op == UserOperation.CreatePostLike) {
let res: CreatePostLikeResponse = msg;
diff --git a/ui/src/components/modlog.tsx b/ui/src/components/modlog.tsx
index 853bdd20..894887ae 100644
--- a/ui/src/components/modlog.tsx
+++ b/ui/src/components/modlog.tsx
@@ -228,6 +228,7 @@ export class Modlog extends Component<any, ModlogState> {
} else if (op == UserOperation.GetModlog) {
let res: GetModlogResponse = msg;
this.state.loading = false;
+ window.scrollTo(0,0);
this.setCombined(res);
}
}
diff --git a/ui/src/components/navbar.tsx b/ui/src/components/navbar.tsx
index 6861461c..84471145 100644
--- a/ui/src/components/navbar.tsx
+++ b/ui/src/components/navbar.tsx
@@ -144,6 +144,10 @@ export class Navbar extends Component<any, NavbarState> {
parseMessage(msg: any) {
let op: UserOperation = msgOp(msg);
if (msg.error) {
+ if (msg.error == "Not logged in.") {
+ UserService.Instance.logout();
+ location.reload();
+ }
return;
} else if (op == UserOperation.GetReplies) {
let res: GetRepliesResponse = msg;
diff --git a/ui/src/components/search.tsx b/ui/src/components/search.tsx
index f066f6ed..7c72939a 100644
--- a/ui/src/components/search.tsx
+++ b/ui/src/components/search.tsx
@@ -251,6 +251,7 @@ export class Search extends Component<any, SearchState> {
this.state.searchResponse = res;
this.state.loading = false;
document.title = `Search - ${this.state.q} - Lemmy`;
+ window.scrollTo(0,0);
this.setState(this.state);
}
diff --git a/ui/src/components/user.tsx b/ui/src/components/user.tsx
index 92ad5335..4cd88abc 100644
--- a/ui/src/components/user.tsx
+++ b/ui/src/components/user.tsx
@@ -342,6 +342,7 @@ export class User extends Component<any, UserState> {
this.state.posts = res.posts;
this.state.loading = false;
document.title = `/u/${this.state.user.name} - Lemmy`;
+ window.scrollTo(0,0);
this.setState(this.state);
} else if (op == UserOperation.EditComment) {
let res: CommentResponse = msg;