Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
21_22-J 38
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
21_22-J 38
21_22-J 38
Commits
5b8b75b4
Commit
5b8b75b4
authored
Apr 27, 2022
by
Lihinikaduwa D.N.R.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Login changed
parent
55d2d8ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
126 additions
and
91 deletions
+126
-91
frontend/src/screen/auth/Login.js
frontend/src/screen/auth/Login.js
+125
-90
frontend/src/screen/client/Client.js
frontend/src/screen/client/Client.js
+1
-1
No files found.
frontend/src/screen/auth/Login.js
View file @
5b8b75b4
import
{
useNavigation
}
from
'
@react-navigation/native
'
;
import
Orientation
from
'
react-native-orientation-locker
'
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
SafeAreaView
,
ScrollView
,
View
,
StyleSheet
,
ImageBackground
,
Text
,
TextInput
,
TouchableOpacity
,
Image
}
from
"
react-native
"
;
import
{
useSelector
,
useDispatch
}
from
'
react-redux
'
;
import
{
userLogin
}
from
'
../../store/actions/login
'
;
import
client
from
"
../client/Client
"
;
const
isValidObjectField
=
(
obj
)
=>
{
return
Object
.
values
(
obj
).
every
(
value
=>
value
.
trim
());
}
import
React
,
{
useState
}
from
'
react
'
;
import
{
SafeAreaView
,
ScrollView
,
View
,
StyleSheet
,
ImageBackground
,
Text
,
TextInput
,
TouchableOpacity
,
Image
,
}
from
'
react-native
'
;
import
client
from
'
../client/Client
'
;
const
isValidObjectField
=
obj
=>
{
return
Object
.
values
(
obj
).
every
(
value
=>
value
.
trim
());
};
const
updateError
=
(
error
,
stateUpdater
)
=>
{
stateUpdater
(
error
);
...
...
@@ -26,23 +34,10 @@ const isValidEmail = value => {
const
Login
=
()
=>
{
const
navigation
=
useNavigation
();
const
dispatch
=
useDispatch
();
const
users
=
useSelector
(
state
=>
state
.
users
.
users
);
const
navigation
=
useNavigation
();
React
.
useEffect
(()
=>
{
const
unsubscribe
=
navigation
.
addListener
(
"
focus
"
,
()
=>
{
Orientation
.
unlockAllOrientations
();
Orientation
.
lockToPortrait
();
});
return
unsubscribe
;
},
[
navigation
]);
const
[
userInfo
,
setUserInfo
]
=
useState
({
email
:
''
,
password
:
''
,
React
.
useEffect
(()
=>
{
const
unsubscribe
=
navigation
.
addListener
(
'
focus
'
,
()
=>
{
Orientation
.
unlockAllOrientations
();
Orientation
.
lockToPortrait
();
});
return
unsubscribe
;
},
[
navigation
]);
...
...
@@ -67,75 +62,115 @@ const Login = () => {
return
updateError
(
'
Required all fields!
'
,
setError
);
}
const
loginHandler
=
()
=>
{
const
loggedInUser
=
users
.
find
(
user
=>
user
.
email
===
email
&&
user
.
password
===
password
)
if
(
loggedInUser
){
console
.
log
(
loggedInUser
);
dispatch
(
userLogin
({
name
:
loggedInUser
.
name
,
id
:
loggedInUser
.
uid
}));
navigation
.
navigate
(
'
Home
'
);
}
else
{
console
.
log
(
'
Invalid user credentials...
'
);
}
}
const
submitForm
=
()
=>
{
if
(
isValidForm
()){
loginFun
(
userInfo
)
}
if
(
!
isValidEmail
(
email
))
{
return
updateError
(
'
Invalid email !
'
,
setError
);
}
if
(
!
password
.
trim
()
||
password
.
length
<
8
)
{
return
updateError
(
'
Password is less than 8 characters !
'
,
setError
);
}
return
(
<
SafeAreaView
>
<
ScrollView
>
<
View
style
=
{
styles
.
continer
}
>
<
ImageBackground
style
=
{
styles
.
backgroundImage
}
source
=
{
require
(
'
../../assets/login/login_background.png
'
)}
resizeMode
=
"
cover
"
>
<
View
>
<
Image
style
=
{
styles
.
logo
}
source
=
{
require
(
'
../../assets/login/logo1.png
'
)}
resizeMode
=
"
contain
"
><
/Image
>
<
/View
>
<
View
elevation
=
{
5
}
style
=
{
styles
.
main_container
}
>
<
Text
style
=
{
styles
.
main_title
}
>
Sign
In
<
/Text
>
{
error
?
(
<
Text
style
=
{{
color
:
'
red
'
,
fontSize
:
18
,
textAlign
:
'
center
'
}}
>
{
error
}
<
/Text>
)
: null
}
<
View
style
=
{
styles
.
form_input
}
>
<
TextInput
id
=
"
email
"
value
=
{
email
}
autoCapitalize
=
"
none
"
onChangeText
=
{
value
=>
handleOnChangeText
(
value
,
'
email
'
)}
style
=
{
styles
.
text_input
}
placeholder
=
"
Enter Email
"
><
/TextInput
>
<
/View
>
<
View
style
=
{
styles
.
form_input
}
>
<
TextInput
id
=
"
password
"
value
=
{
password
}
autoCapitalize
=
"
none
"
secureTextEntry
onChangeText
=
{
value
=>
handleOnChangeText
(
value
,
'
password
'
)}
style
=
{
styles
.
text_input
}
placeholder
=
"
Enter Password
"
><
/TextInput
>
<
/View
>
<
View
style
=
{
styles
.
form_input
}
>
<
TouchableOpacity
onPress
=
{
()
=>
{
navigation
.
navigate
(
"
Start
"
);}}
style
=
{
styles
.
btn
}
>
<
Text
style
=
{
styles
.
btn_text
}
>
Sign
In
<
/Text
>
<
/TouchableOpacity
>
<
/View
>
{
/* onPress={submitForm} */
}
<
View
style
=
{
styles
.
text_if
}
>
<
TouchableOpacity
onPress
=
{()
=>
{
navigation
.
navigate
(
"
Register
"
)}}
>
<
Text
style
=
{
styles
.
btn_text2
}
>
If
you
don
'
t have account? Sign Up
</Text>
</TouchableOpacity>
</View>
</View>
</ImageBackground>
</View>
</ScrollView>
</SafeAreaView>
)
}
return
true
;
};
const
submitForm
=
()
=>
{
if
(
isValidForm
())
{
loginFun
(
userInfo
);
}
};
const
loginFun
=
()
=>
{
var
formData
=
JSON
.
stringify
(
userInfo
);
client
.
post
(
'
login
'
,
formData
,
{
headers
:
{
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
},
})
.
then
(
response
=>
{
console
.
log
(
response
.
data
);
if
(
response
.
data
.
status
==
404
)
{
return
updateError
(
'
Please register our system
'
,
setError
);
}
if
(
response
.
data
.
status
==
200
)
{
return
navigation
.
navigate
(
'
Start
'
);
}
})
.
catch
(
err
=>
{
console
.
log
(
err
);
});
};
return
(
<
SafeAreaView
>
<
ScrollView
>
<
View
style
=
{
styles
.
continer
}
>
<
ImageBackground
style
=
{
styles
.
backgroundImage
}
source
=
{
require
(
'
../../assets/login/login_background.png
'
)}
resizeMode
=
"
cover
"
>
<
View
>
<
Image
style
=
{
styles
.
logo
}
source
=
{
require
(
'
../../assets/login/logo1.png
'
)}
resizeMode
=
"
contain
"
><
/Image
>
<
/View
>
<
View
elevation
=
{
5
}
style
=
{
styles
.
main_container
}
>
<
Text
style
=
{
styles
.
main_title
}
>
Sign
In
<
/Text
>
{
error
?
(
<
Text
style
=
{{
color
:
'
red
'
,
fontSize
:
18
,
textAlign
:
'
center
'
}}
>
{
error
}
<
/Text
>
)
:
null
}
<
View
style
=
{
styles
.
form_input
}
>
<
TextInput
id
=
"
email
"
value
=
{
email
}
autoCapitalize
=
"
none
"
onChangeText
=
{
value
=>
handleOnChangeText
(
value
,
'
email
'
)}
style
=
{
styles
.
text_input
}
placeholder
=
"
Enter Email
"
><
/TextInput
>
<
/View
>
<
View
style
=
{
styles
.
form_input
}
>
<
TextInput
id
=
"
password
"
value
=
{
password
}
autoCapitalize
=
"
none
"
secureTextEntry
onChangeText
=
{
value
=>
handleOnChangeText
(
value
,
'
password
'
)}
style
=
{
styles
.
text_input
}
placeholder
=
"
Enter Password
"
><
/TextInput
>
<
/View
>
<
View
style
=
{
styles
.
form_input
}
>
<
TouchableOpacity
onPress
=
{
submitForm
}
style
=
{
styles
.
btn
}
>
<
Text
style
=
{
styles
.
btn_text
}
>
Sign
In
<
/Text
>
<
/TouchableOpacity
>
<
/View
>
{
/* onPress={submitForm} */
}
<
View
style
=
{
styles
.
text_if
}
>
<
TouchableOpacity
onPress
=
{()
=>
{
navigation
.
navigate
(
'
Register
'
);
}}
>
<
Text
style
=
{
styles
.
btn_text2
}
>
If
you
don
'
t have account? Sign Up
</Text>
</TouchableOpacity>
</View>
</View>
</ImageBackground>
</View>
</ScrollView>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
continer: {
...
...
frontend/src/screen/client/Client.js
View file @
5b8b75b4
...
...
@@ -2,6 +2,6 @@ import axios from 'axios';
// export default axios.create({ baseURL: 'http://192.168.8.102:5000/', timeout: 15000, });
export
default
axios
.
create
({
baseURL
:
'
http://192.168.1.10
1
:5000/
'
,
baseURL
:
'
http://192.168.1.10
0
:5000/
'
,
timeout
:
15000
,
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment