コード例 #1
0
        public userapp Actualizar(int id, string telephone, string cellphone, string email, string contrasena)
        {
            db.Configuration.LazyLoadingEnabled = false;

            userapp user = db.userapp.Find(id);

            if (user != null)
            {
                user.telephone = telephone;
                user.cellphone = cellphone;
                user.email     = email;
                user.passw     = MD5Manager.Encrypt(contrasena, true);

                string pass = MD5Manager.Encrypt(contrasena, true);
                db.Entry(user).State = EntityState.Modified;



                db.SaveChanges();

                return(user);
            }

            return(null);
        }
コード例 #2
0
        public userapp Login(string email, string pass)
        {
            db.Configuration.LazyLoadingEnabled = false;

            pass = MD5Manager.Encrypt(pass, true);
            List <userapp> user = db.userapp.Where(r => r.email.Equals(email)).Where(r => r.passw.Equals(pass)).ToList();

            if (user.Count > 0)
            {
                userapp userapp = user.ElementAt(0);
                return(userapp);
            }

            return(null);
        }
コード例 #3
0
        public void sendemail(userapp user, string email)
        {
            user.passw = CreatePassword(6);


            var          fromAddress  = new MailAddress("*****@*****.**", "Se le tiene");
            var          toAddress    = new MailAddress(user.email, "To Name");
            const string fromPassword = "******";
            const string subject      = "Cambio de contraseña";
            string       body         = "<h3>Cordial saludo</h3><h3 style=\"text-align: justify;\">Tu nueva contraseña es " + user.passw + "</p>";

            user.passw = MD5Manager.Encrypt(user.passw, true);

            db.Entry(user).State = EntityState.Modified;
            db.SaveChanges();
            try
            {
                var smtp = new SmtpClient
                {
                    Host                  = "72.29.75.91",
                    Port                  = 25,
                    EnableSsl             = false,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Timeout               = 10000,
                    Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
                };
                var message = new MailMessage(fromAddress, toAddress);

                message.IsBodyHtml = true;
                message.Subject    = subject;
                message.Body       = body;



                smtp.EnableSsl = false;
                smtp.Send(message);
            }


            catch (Exception e)
            {
                Console.WriteLine("Ouch!" + e.ToString());
            }
        }
コード例 #4
0
        public async Task <IHttpActionResult> Postuserapp(userapp userapp)
        {
            db.Configuration.LazyLoadingEnabled = false;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                List <userapp> user = db.userapp.Where(r => r.email.Equals(userapp.email)).ToList();
                if (user.Count > 0)
                {
                    return(Content(HttpStatusCode.BadRequest, "Usuario existente"));
                }
                userapp.passw  = MD5Manager.Encrypt(userapp.passw, true);
                userapp.status = 1;
                db.userapp.Add(userapp);
                await db.SaveChangesAsync();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            return(Ok(userapp));
        }