Skip to content

Commit

Permalink
Merge pull request #25 from kirkchen/implement_login_feature
Browse files Browse the repository at this point in the history
Implement login feature
  • Loading branch information
KeaNy committed Jun 7, 2015
2 parents 1934b13 + 9894073 commit cd18ee6
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 62 deletions.
82 changes: 82 additions & 0 deletions app/components/nav/nav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
var React = require('react/addons');
var $ = require('jquery');

var Nav = React.createClass({
getInitialState: function () {
return {
hideMenu: true,
isLogin: false,
user: null
}
},
componentDidMount: function () {
var self = this;
$.get('/api/login/getStatus')
.then(function (result) {
self.setState({
isLogin: result.isLogin,
user: result.user
});
});
},
handleToggleMenu: function () {
this.setState({
hideMenu: !this.state.hideMenu
})
},
render: function () {
var cx = React.addons.classSet;
var logoClass = cx({
'nav-logo': true,
'hide': !this.state.hideMenu
});
var menuClass = cx({
'nav-menu': true,
'hide': this.state.hideMenu
});

return (
<nav className="nav">
<div className={ logoClass }
onClick={ this.handleToggleMenu }>
<h1>K</h1>
</div>
<div className={ menuClass }
onMouseLeave={ this.handleToggleMenu }>
<ul className="nav-menu-list">
<li className="nav-menu-item">
<a title="回首頁" href="/">
<i className="icon icons-keanux">K</i>
<span className="nav-menu-title">
首頁
</span>
</a>
</li>
{this.state.isLogin ?
<li className="nav-menu-item">
<a title="到個人頁面" href="#">
<i className="icon icons-avatar">
<img src={ this.state.user.photo }/>
</i>
<span className="nav-menu-title">
{ this.state.user.nickname }
</span>
</a>
</li> :
<li className="nav-menu-item">
<a title="Login" href="api/login/facebook">
<span className="nav-menu-title">
Facebook Login
</span>
</a>
</li>
}
</ul>
</div>
</nav>
);
}
})
;

module.exports = Nav;
10 changes: 7 additions & 3 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
var React = require('react');

// Related Control
var PostBox = require('./components/post/postbox');
var PostBox = require('./components/post/PostBox');
var Nav = require('./components/nav/nav');

React.render(
<PostBox url="/api/posts" />,
document.getElementById('content')
<div>
<Nav />
<PostBox url="/api/posts" />
</div>
, document.getElementById('content')
);
5 changes: 4 additions & 1 deletion data/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ Models.sequelize.sync({force: true}).then(function () {
// Add new User
Models.User.create({
name: 'keanyc',
nickname: 'KeaNy'
nickname: 'KeaNy',
provider: 'Facebook',
loginId: '10204525184038018',
photo: 'https://graph.facebook.com/keanyc/picture?width=120&height=120'
})
.then(function (user) {

Expand Down
5 changes: 4 additions & 1 deletion models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ module.exports = function (sequelize, DataTypes) {
"User",
{
name: DataTypes.STRING,
nickname: DataTypes.STRING
nickname: DataTypes.STRING,
provider: DataTypes.ENUM('Local', 'Facebook'),
loginId: DataTypes.STRING,
photo: DataTypes.STRING
},
{
classMethods: {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
"body-parser": "~1.0.1",
"connect-browserify": "^4.0.0",
"express": "~4.0.0",
"express-session": "^1.11.2",
"jquery": "^2.1.4",
"mysql": "git://github.com/felixge/node-mysql.git",
"node-jsx": "^0.13.3",
"passport": "^0.2.2",
"passport-facebook": "^2.0.0",
"react": "^0.13.3",
"react-ago-component": "^0.6.1",
"reactify": "^1.1.1",
Expand Down
200 changes: 155 additions & 45 deletions public/css/base.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
body {
font-family: "Microsoft Jhenghei", "ff-tisa-web-pro",Georgia,Cambria,"Times New Roman",Times,serif;
font-family: "Microsoft Jhenghei", "ff-tisa-web-pro", Georgia, Cambria, "Times New Roman", Times, serif;
}

a {
Expand All @@ -8,84 +8,194 @@ a {
}

h1 {
font-family: Georgia,Cambria,"Times New Roman",Times,serif;
font-size: 50px;
text-shadow: 0 1px 3px rgba(0,0,0,0.3);
margin-bottom: 30px;
margin-top: 12px;
text-align: center;
font-family: Georgia, Cambria, "Times New Roman", Times, serif;
font-size: 50px;
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
margin-bottom: 30px;
margin-top: 12px;
text-align: center;
}

h2 {
padding: 0;
margin-top: 16px;
margin-bottom: 4px;
padding: 0;
margin-top: 16px;
margin-bottom: 4px;
}

h3 {
padding: 0;
margin: 0;
color: rgba(0,0,0,0.3);
font-weight: normal;
padding: 0;
margin: 0;
color: rgba(0, 0, 0, 0.3);
font-weight: normal;
}

p, ul {
margin: 0;
}

#content {
width: 100%;
max-width: 700px;
overflow: hidden;
margin: 0 auto;
width: 100%;
max-width: 700px;
overflow: hidden;
margin: 0 auto;
}

img {
max-width: 100%;
max-width: 100%;
}

.show{
display: block;
}

.hide {
display: none;
}

/* Post */
.post {
border-bottom: 1px solid #ccc;
margin-bottom: 50px;
padding-bottom: 50px;
border-bottom: 1px solid #ccc;
margin-bottom: 50px;
padding-bottom: 50px;
}

.postAuthor {
margin-top: 4px;
margin-top: 4px;
}

.postTitle {
font-size: 42px;
font-size: 42px;
}

.postContent {
/*display: none;*/
font-size: 18px;
line-height: 30px;
margin-top: 30px;
overflow: hidden;
height: 90px;
/*display: none;*/
font-size: 18px;
line-height: 30px;
margin-top: 30px;
overflow: hidden;
height: 90px;
}

.postMetaInline-avatar {
width: 36px;
height: 36px;
display: table-cell;
width: 36px;
height: 36px;
display: table-cell;
}

.avatar-image {
width: 100%;
height: 100%;
border-radius: 100%;
width: 100%;
height: 100%;
border-radius: 100%;
}

.postMetaInline-feedSummary {
display: table-cell;
vertical-align: middle;
font-size: 14px;
line-height: 1.4;
padding-left: 10px;
display: table-cell;
vertical-align: middle;
font-size: 14px;
line-height: 1.4;
padding-left: 10px;
}

.postMetaInline--supplemental {
display: block;
color: rgba(0,0,0,0.3);
font-size: 12px;
line-height: 1.1;
display: block;
color: rgba(0, 0, 0, 0.3);
font-size: 12px;
line-height: 1.1;
}

/* Nav */
.nav {
position: absolute;
top: 0;
left: 0;
bottom: 0;
outline: 0;
background-color: #232322;
z-index: 300;
}

.nav-logo {
box-sizing: initial;
cursor: pointer;
position: absolute;
top: 10px;
left: 10px;
padding: 8px;
height: 26px;
width: 26px;
z-index: 700;
background-color: #333332;
text-align: center;
border: 0;
-webkit-border-radius: 100%;
-moz-border-radius: 100%;
border-radius: 100%;
}

.nav-logo h1 {
font-family: Georgia, Cambria, "Times New Roman", Times, serif;
margin: 0;
padding: 0;
line-height: 26px;
font-size: 22px;
color: #FFF;
}

.nav-menu {
text-align: left;
background: #ccc;
width: 280px;
height: 100%;
}

.nav-menu-list {
list-style-type: none;
padding-top: 10px;
padding-left: 20px;
}

.nav-menu-item {
padding: 5px;
line-height: 24px;
color: #555;
font-size: 14px;
font-weight: bold;
}

.nav-menu-title {
line-height: 24px;
vertical-align: text-bottom;
}

/* Icon */
.icon {
font-style: normal;
display: inline-block;
vertical-align: baseline;
width: 24px;
height: 24px;
margin-right: 15px;
}

.icons-search {
background-image: url(../img/search.png);
background-size: 18px 18px !important;
background-repeat: no-repeat;
}

.icons-keanux {
color: #000;
font-family: Georgia, Cambria, "Times New Roman", Times, serif;
font-size: 22px;
font-weight: bold;
}

.icons-avatar {
color: #FFF;
}

.icons-avatar img {
-webkit-border-radius: 100%;
-moz-border-radius: 100%;
border-radius: 100%;
}
Loading

0 comments on commit cd18ee6

Please sign in to comment.