-
Notifications
You must be signed in to change notification settings - Fork 0
/
registro.aspx_b.cs
207 lines (192 loc) · 8.89 KB
/
registro.aspx_b.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
using System;
using System.Configuration;
using System.Net;
using System.IO;
using System.Web.Script.Serialization;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Security;
using System.Collections;
using Newtonsoft.Json;
using System.Net.Mail;
namespace MasTicket
{
public partial class registro : System.Web.UI.Page
{
wsac.IsacClient ws;
DatosRedes datosredes = null;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Form.Count > 0)
{
datosredes = JsonConvert.DeserializeObject<DatosRedes>(Request.Form[0]);
Session["datosredes"] = datosredes;
ws = Session["wsac"] as wsac.IsacClient;
if (datosredes.email != null && !datosredes.email.Equals(""))
{
string json = ws.GetUser(0, check.SafeSqlLiteral(datosredes.email), "");
List<Usuario> lu = JsonConvert.DeserializeObject<List<Usuario>>(json);
if (lu.Count > 0)
{
if (lu.FirstOrDefault().idusuario == -1)
spnJS.Text = "<script>msgError('El usuario se encuentra bloqueado. Revise el correo con el que se registro'); </script>";
else
{
Session["idusrlogged"] = lu.FirstOrDefault().idusuario;
Session["usrlogged"] = lu.FirstOrDefault();
if (Session["RecargaPendiente"] != null)
{
if (bool.Parse(Session["RecargaPendiente"].ToString()))
{
RecargasViewModel rvm = Session["rvm"] as RecargasViewModel;
rvm.IdUsuario = lu.FirstOrDefault().idusuario;
TarjetasViewModel tvm = Session["tvm"] as TarjetasViewModel;
tvm.Idusuario = lu.FirstOrDefault().idusuario;
Response.Redirect("confir_recarga.aspx");
}
else
{
Response.Redirect("datosrecarga.aspx");
}
}
else
{
Response.Redirect("datosrecarga.aspx");
}
}
}
else
{
txtNombre.Value = datosredes.name;
txtEmail.Value = datosredes.email;
imgFoto.ImageUrl = datosredes.picture.data.url;
}
}
else
{
spnJS.Text = "<script>msgError('Error al logearse con redes sociales'); </script>";
}
}
}
btnRegistrar.Click += async (s, ea) =>
{
string nip1 = "", nip2 = "", email = "", nombre = "", numero = "";
nip1 = check.SafeSqlLiteral(txtNip1.Value.Trim());
nip2 = check.SafeSqlLiteral(txtNip2.Value.Trim());
email = check.SafeSqlLiteral(txtEmail.Value.Trim());
nombre = check.SafeSqlLiteral(txtNombre.Value.Trim());
numero = check.SafeSqlLiteral(txtNumero.Value.Trim());
//verificador de correo
Random r = new Random();
int verif = r.Next(100000, 999999);
if (nip1 != nip2)
{
spnJS.Text = "<script>msgError('Los 2 nips deben ser iguales');</script>";
return;
}
else
{
if (!check.ValidaNip(nip1))
{
spnJS.Text = "<script>msgError('Revise el NIP. (No se permiten consecutivos ni que todos los digitos sean iguales)');</script>";
return;
}
else
spnJS.Text = "";
}
ws = Session["wsac"] as wsac.IsacClient;
string json = ws.GetUser(0, check.SafeSqlLiteral(email), "");
List<Usuario> lu = JsonConvert.DeserializeObject<List<Usuario>>(json);
if (lu.Count > 0)
{
spnJS.Text = "<script>msgError('Ya existe un usuario con este email. Inicie sesion con su NIP');</script>";
return;
}
else
{
spnJS.Text = "";
wsac.Usuario u = new wsac.Usuario()
{
numerocontacto = numero,
email = email,
name = nombre,
nip = nip1,
fechaalta = DateTime.Now,
verificacion = nip1 + verif,
idpais = int.Parse(Session["idpais"].ToString())
};
if (Session["datosredes"] != null)
datosredes = Session["datosredes"] as DatosRedes;
if (datosredes != null)
{
u.first_name = check.SafeSqlLiteral(!String.IsNullOrEmpty(datosredes.first_name) ? datosredes.first_name : "");
u.last_name = check.SafeSqlLiteral(!String.IsNullOrEmpty(datosredes.last_name) ? datosredes.last_name : "");
u.gender = check.SafeSqlLiteral(!String.IsNullOrEmpty(datosredes.gender) ? datosredes.gender : "");
u.picture = check.SafeSqlLiteral(!String.IsNullOrEmpty(datosredes.picture.data.url) ? datosredes.picture.data.url : "");
}
wsac.AltaUsrResponse res = await ws.AltaUsrAsync(u,0);
if (res.Body.AltaUsrResult > 0)
{
Session["idusrlogged"] = res.Body.AltaUsrResult;
Session["datosredes"] = null;
if (Session["RecargaPendiente"] != null)
{
if (bool.Parse(Session["RecargaPendiente"].ToString()))
{
RecargasViewModel rvm = Session["rvm"] as RecargasViewModel;
rvm.IdUsuario = res.Body.AltaUsrResult;
TarjetasViewModel tvm = Session["tvm"] as TarjetasViewModel;
tvm.Idusuario = res.Body.AltaUsrResult;
Response.Redirect("confir_recarga.aspx");
// spnJS.Text = "<script>alert('Revise su mail de confirmación');</script>";
// enviaMail(u.email,u.verificacion);
// Session["bienvenido"] = true;
// Response.Redirect("datosrecarga.aspx");
}
else
{
//spnJS.Text = "<script>alert('Revise su mail de confirmación');</script>";
Session["bienvenido"] = true;
Response.Redirect("datosrecarga.aspx");
}
}
else
{
//spnJS.Text = "<script>alert('Revise su mail de confirmación');</script>";
Session["bienvenido"] = true;
Response.Redirect("datosrecarga.aspx");
}
}
else
{
spnJS.Text = "<script>msgError('Ocurrio un error. Contacte al administrador');</script>";
return;
}
};
};
}
}
public class DatosRedes
{
public string first_name { get; set; }
public string last_name { get; set; }
public string name { get; set; }
public string gender { get; set; }
public string email { get; set; }
public Picture picture { get; set; }
}
public class Picture
{
public DataPicture data { get; set; }
}
public class DataPicture
{
public bool is_silhouette { get; set; }
public string url { get; set; }
}
}