Guest User

Untitled

a guest
Mar 22nd, 2017
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.92 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. StyleSheet,
  4. Text,
  5. View,
  6. Image,
  7. Dimensions,
  8. TextInput,
  9. ScrollView,
  10. AsyncStorage,
  11. TouchableOpacity,
  12. TouchableWithoutFeedback,
  13. ListView,
  14. BackAndroid,
  15.  
  16. } from 'react-native';
  17. import { Pulse } from 'react-native-loader';
  18. import renderIf from '../../RenderIf';
  19.  
  20. export default class ChangePassword extends Component {
  21. constructor(props) {
  22. super(props);
  23.  
  24. AsyncStorage.multiGet(['firstName','lastName','username'], (err, keys) => {
  25. this.setState({
  26. firstName: keys[0][1],
  27. lastName: keys[1][1],
  28. username: keys[2][1]
  29.  
  30. })
  31. console.log("key dayta = "+keys);
  32. global.abcd = keys[2][1];
  33. });
  34.  
  35.  
  36.  
  37. this.state = {
  38.  
  39. current_password: '',
  40. new_password:'',
  41. confirm_password: '',
  42. username:'',
  43. errorPassword:false,
  44. loading: false,
  45. };
  46.  
  47.  
  48.  
  49. }
  50.  
  51. account(){
  52. this.props.navigator.pop({
  53. id: 'account',
  54.  
  55. })
  56. }
  57.  
  58.  
  59.  
  60.  
  61. changePasswordAttempt() {
  62. // let abc = AsyncStorage.getItem('username');
  63. let current_password = this.state.current_password;
  64. let new_password = this.state.new_password;
  65. let confirm_password = this.state.confirm_password;
  66. let username = this.state.username;
  67. console.log("current = " +current_password);
  68. console.log("new = " +new_password);
  69. console.log("confirm = " +confirm_password);
  70. console.log("username = " +username);
  71.  
  72. if(current_password == "" || current_password == undefined){
  73. this.setState({
  74. errorPassword: true,
  75. currentPassword : 'current Password cant be empty',
  76. });
  77. }
  78. else if(new_password == "" || new_password == undefined){
  79. this.setState({
  80. errorPassword: true,
  81. newPassword : 'new password cant be empty',
  82. });
  83. }
  84. else if(confirm_password == "" || confirm_password == undefined){
  85. this.setState({
  86. errorPassword: true,
  87. confirmPassword : 'confirm password cant be empty',
  88. });
  89. }
  90. else{
  91.  
  92.  
  93.  
  94.  
  95.  
  96. if(new_password == confirm_password){
  97. this.setState({
  98. loading: true,
  99.  
  100. });
  101. let bodyParam =JSON.stringify({
  102. username: username,
  103. current_password: current_password,
  104. new_password: new_password
  105. })
  106. console.log(bodyParam);
  107. fetch('https://ro47ygzbi3.execute-api.ap-southeast-1.amazonaws.com/Development/changepassword', {
  108. method: 'POST',
  109. body: bodyParam,
  110. headers: {
  111. "x-api-key": "NFeUWGieM17AIJTnFqMUK94RpAoOgDZdhG8WzaVe",
  112. "Content-Type":"application/json;charset=utf-8",
  113. "url" : "ro47ygzbi3.execute-api.ap-southeast-1.amazonaws.com"
  114. }
  115. })
  116. .then((response) => {
  117. let responseJson = JSON.parse(response._bodyInit);
  118. if(responseJson.status == "ok"){
  119. console.log("data inserted successfully");
  120. console.log("password updated successfully");
  121. this.setState({
  122. loading: false,
  123.  
  124. });
  125. }else{
  126. console.log("error in post api");
  127. console.log(responseJson.status);
  128. }
  129. })
  130. }
  131. else{
  132. console.log("password doesn't match");
  133. this.setState({
  134. errorPassword: true,
  135. passwordNotMatch : 'New password and Confirm Password Doesnt Match',
  136. });
  137. }
  138.  
  139. }
  140.  
  141. }
  142. render() {
  143. return (
  144. <View style={styles.container}>
  145. <View style={styles.header}>
  146. <View style={styles.cancel}>
  147. <TouchableOpacity
  148. style={styles.loginBtn}
  149. onPress={this.account.bind(this)}
  150. >
  151. <Text style={styles.headerCancel}>Cancel</Text>
  152. </TouchableOpacity>
  153. </View>
  154.  
  155. </View>
  156.  
  157. <View>
  158. <Text style={styles.changePasswordText}>Change Password</Text>
  159.  
  160. </View>
  161. <ScrollView style={styles.profileForm}
  162. showsVerticalScrollIndicator={true}
  163. automaticallyAdjustContentInsets={false}
  164. // keyboardDismissMode='on-drag'
  165. keyboardShouldPersistTaps="always"
  166. >
  167. {renderIf(this.state.loading)(
  168. <View style={styles.loadingContainer}>
  169. <Pulse size={30} color="orange" />
  170. <Text style={styles.loadingUpdate}>Updating Password ....</Text>
  171. </View>
  172. )}
  173. <View style={styles.form}>
  174. <Text style={styles.inputhead}>Current Password</Text>
  175. <TextInput
  176. secureTextEntry={true}
  177. style={styles.inputDetail}
  178. returnKeyType="next"
  179. autoCapitalize="none"
  180. autoCorrect={false}
  181. onChangeText={(current_password) => this.setState({current_password})}
  182. />
  183. {renderIf(this.state.errorPassword)(
  184. <View style={styles.loadingContainerError}>
  185. <Text style={styles.errorChangePassword}>{this.state.currentPassword}</Text>
  186. </View>
  187. )}
  188.  
  189. <Text style={styles.inputhead}>New Password</Text>
  190. <TextInput
  191. secureTextEntry={true}
  192. style={styles.inputDetail}
  193. returnKeyType="next"
  194. autoCapitalize="none"
  195. autoCorrect={false}
  196. onChangeText={(new_password) => this.setState({new_password})}
  197. // onBlur={(firstNameMsg) => this.setState('')}
  198. // onBlur={this.setState({errorLogin: true})}
  199. // value={this.state.first_name}
  200. />
  201. {renderIf(this.state.errorPassword)(
  202. <View style={styles.loadingContainerError}>
  203. <Text style={styles.errorChangePassword}>{this.state.newPassword}</Text>
  204. </View>
  205. )}
  206. <Text style={styles.inputhead}>Confirm Password</Text>
  207. <TextInput
  208. secureTextEntry={true}
  209. style={styles.inputDetail}
  210. returnKeyType="next"
  211. autoCapitalize="none"
  212. autoCorrect={false}
  213. onChangeText={(confirm_password) => this.setState({confirm_password})}
  214. // onBlur={(firstNameMsg) => this.setState('')}
  215. // onBlur={this.setState({errorLogin: true})}
  216. // value={this.state.first_name}
  217. />
  218. {renderIf(this.state.errorPassword)(
  219. <View style={styles.loadingContainerError}>
  220. <Text style={styles.errorChangePassword}>{this.state.passwordNotMatch}</Text>
  221. </View>
  222. )}
  223. {renderIf(this.state.errorPassword)(
  224. <View style={styles.loadingContainerError}>
  225. <Text style={styles.errorChangePassword}>{this.state.confirmPassword}</Text>
  226. </View>
  227. )}
  228. <TouchableOpacity
  229. style={styles.mainBtn}
  230. onPress={this.changePasswordAttempt.bind(this)}
  231. >
  232. <Text style={styles.mainBtnText}>Reset Password</Text>
  233. </TouchableOpacity>
  234. </View>
  235. </ScrollView>
  236. </View>
  237. );
  238. }
  239. }
  240.  
  241. const styles = StyleSheet.create({
  242. container: {
  243. flex: 1,
  244. // padding: 10,
  245. backgroundColor: '#FFFFFF'
  246. },
  247. form:{
  248. margin:25,
  249. },
  250. inputText: {
  251. color: "black",
  252. marginTop: 10
  253. },
  254. inputhead:{
  255. color: "black",
  256. // textAlign:"center"
  257. },
  258. mainBtn: {
  259. marginTop: 10,
  260. borderWidth: 1,
  261. borderColor: "white",
  262. borderRadius: 4,
  263. padding: 7,
  264. width: window.width * 0.7,
  265. alignItems: "center",
  266. backgroundColor:"orange"
  267. },
  268. mainBtnText: {
  269. color: "white"
  270. },
  271. header: {
  272. backgroundColor:"#f5f6f6",
  273. marginBottom: 15,
  274. flexDirection: "row",
  275. justifyContent: "center",
  276. alignItems: "center"
  277. },
  278. changePasswordText: {
  279. fontSize: 17,
  280. textAlign: "center",
  281. marginTop: 20,
  282. marginBottom: 20,
  283. color:"black"
  284. },
  285. cancel: {
  286. flex: 0.2,
  287. // justifyContent: "center",
  288. // alignItems: "center"
  289. marginLeft:10,
  290. },
  291. headerCancel :{
  292. fontSize: 17,
  293. color: "#f6a73c",
  294. marginTop: 20,
  295. marginBottom: 20
  296. },
  297. loadingContainerError: {
  298. width: window.width * 0.7,
  299. alignItems: "center",
  300. marginTop: 10
  301. },
  302. errorChangePassword: {
  303. color: "red",
  304. fontSize: 12
  305. },
  306. loadingContainer: {
  307. // width: window.width * 0.7,
  308. alignItems: "center",
  309. // marginTop: 10,
  310. position: 'absolute',
  311. // width: 100,
  312. // height: 100,
  313. top: 100,
  314. left: 100,
  315. // backgroundColor: 'green',
  316. },
  317. loadingUpdate:{
  318. fontSize:20,
  319. color:'orange',
  320. }
  321.  
  322. });
  323.  
  324. //AppRegistry.registerComponent('ChangePassword', () => ChangePassword);
Add Comment
Please, Sign In to add comment