Guest User

Untitled

a guest
Jan 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. import 'package:rezervisanje/login/connect.dart' as conn;
  2.  
  3. class FirstTime extends StatefulWidget {
  4. final Color primaryColor;
  5. final Color backgroundColor;
  6.  
  7. FirstTime({Key key, this.primaryColor, this.backgroundColor});
  8. @override
  9. _FirstTimeState createState() => new _FirstTimeState();
  10. }
  11.  
  12. class _FirstTimeState extends State<FirstTime> {
  13. var exe = "exe";
  14. var pass, email;
  15. bool _autoValidate = false;
  16. String _validateEmail(String value) {
  17. if (value.isEmpty) {
  18.  
  19. return "Email";
  20. }
  21.  
  22. String p = "[a-zA-Z0-9+._%-+]{1,256}" +
  23. "\@" +
  24. "[a-zA-Z0-9][a-zA-Z0-9\-]{0,64}" +
  25. "(" +
  26. "\." +
  27. "[a-zA-Z0-9][a-zA-Z0-9\-]{0,25}" +
  28. ")+";
  29. RegExp regExp = new RegExp(p);
  30.  
  31. if (regExp.hasMatch(value)) {
  32.  
  33. return null;
  34. }
  35. return 'bad email!';
  36. }
  37.  
  38. void _submit() {
  39. if (formKey.currentState.validate()) {
  40. try {
  41. formKey.currentState.save();
  42. conn.validateAndSubmit(email, pass);
  43. if (globals.userID != "") {
  44. Navigator.of(context).push(new MaterialPageRoute(
  45. builder: (BuildContext context) => new HomePage()));
  46. }
  47. } catch (e) {
  48. exe = e.toString();
  49. print(exe);
  50. if (exe != "") {
  51. new Text(exe);
  52. }
  53. if (globals.conex != "") {
  54. new Text(globals.conex);
  55. }
  56. }
  57. } else {
  58. setState(() => _autoValidate = true);
  59. }
  60. }
  61.  
  62. final formKey = GlobalKey<FormState>();
  63.  
  64. @override
  65. Widget build(BuildContext context) {
  66. return new Scaffold(
  67. backgroundColor: Colors.orange,
  68. body: Container(
  69. color: Colors.orange,
  70. child: Padding(
  71. padding: EdgeInsets.all(34.0),
  72. child: Form(
  73. autovalidate: _autoValidate,
  74. key: formKey,
  75. child:
  76. Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
  77. TextFormField(
  78. decoration: InputDecoration(
  79. icon: Icon(Icons.person_outline),
  80. hintText: globals.firstName,
  81. hintStyle: TextStyle(color: Colors.black54),
  82. labelText: "Email"),
  83. validator: _validateEmail,
  84. keyboardType: TextInputType.emailAddress,
  85. onSaved: (input) => email = input,
  86. ),
  87.  
  88. new TextFormField(
  89. decoration: InputDecoration(
  90. icon: Icon(Icons.lock_outline),
  91. labelStyle: new TextStyle(color: Colors.black54),
  92. hintText: globals.lastName,
  93. labelText: "password"),
  94. validator: (input) =>
  95. input.length <= 0 ? 'password needed' : null,
  96. onSaved: (input) => pass = input,
  97. ),
  98. //Last Name TextBox
  99.  
  100. Column(
  101. mainAxisAlignment: MainAxisAlignment.end,
  102. children: <Widget>[
  103. Padding(
  104. padding: const EdgeInsets.all(8.0),
  105. child: RaisedButton(
  106. shape: new RoundedRectangleBorder(
  107. borderRadius: new BorderRadius.circular(30.0)),
  108. color: Colors.deepOrange,
  109. onPressed: _submit,
  110. textColor: Colors.black,
  111. child: Text("login"),
  112. ) //Submit Button
  113. )
  114. ],
  115. ),
  116. Column(
  117. mainAxisAlignment: MainAxisAlignment.end,
  118. children: <Widget>[
  119. Padding(
  120. padding: const EdgeInsets.all(8.0),
  121. child: RaisedButton(
  122. shape: new RoundedRectangleBorder(
  123. borderRadius: new BorderRadius.circular(30.0)),
  124. color: Colors.deepOrange,
  125. textColor: Colors.black,
  126. onPressed: () => Navigator.of(context).push(
  127. new MaterialPageRoute(
  128. builder: (BuildContext context) =>
  129. new Register())),
  130. child: Text("register"),
  131. ) //Submit Button
  132. ),
  133. Padding(
  134. padding: const EdgeInsets.all(8.0),
  135. child: FlatButton(
  136. onPressed: () => Navigator.of(context).push(
  137. new MaterialPageRoute(
  138. builder: (BuildContext context) =>
  139. new PassReset())),
  140. child: Text("forgot password?"),
  141. )),
  142. ],
  143. )
  144. ]),
  145. ),
  146. )));
  147.  
  148. }
  149. }
  150.  
  151. void validateAndSubmit(String email, String password) async {
  152. try {
  153. FirebaseUser user = await FirebaseAuth.instance
  154. .signInWithEmailAndPassword(email: email, password: password);
  155. globals.userID = user.uid;
  156.  
  157. if (globals.userID == "") {
  158. globals.conex = "check your pass or email";
  159. }
  160. } catch (e) {
  161. if (Platform.isIOS) {
  162. globals.conex = e.details;
  163. } else
  164. globals.conex = e.message;
  165. }
  166. }
Add Comment
Please, Sign In to add comment