示例#1
0
        public async Task <IActionResult> Create([Bind("Iduser,Name,Email,Password,ConfirmedByEmail,IsAdmin")] SimpleUser simpleUser)
        {
            if (ModelState.IsValid)
            {
                _context.Add(simpleUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(simpleUser));
        }
示例#2
0
        public async Task <IActionResult> Create(string tinRead)
        {
            var idBooks = tinRead.Split(Environment.NewLine);

            foreach (var id in idBooks)
            {
                var exists = await _context.Book.FirstOrDefaultAsync(it => it.IdtinRead == id);

                if (exists != null)
                {
                    _context.Book.Remove(exists);
                }
                var book = new Book();
                book.IdtinRead = id;
                book.IsCorrect = true;
                try
                {
                    var b = new InfoBook(id);
                    await b.GetInfoFromId();

                    var val = b.Validate(null).FirstOrDefault();
                    book.Title      = b.Title;
                    book.Creator    = b.Creator;
                    book.Identifier = b.Identifier;
                    if (val != null)
                    {
                        book.IsCorrect    = false;
                        book.ErrorMessage = val.ErrorMessage;
                    }
                    else
                    {
                        var l = Guid.NewGuid();//.ToString("N");
                        book.UniqueLink = l.ToString("N");
                        try
                        {
                            if (!io.Directory.Exists("epubs"))
                            {
                                io.Directory.CreateDirectory("epubs");
                            }
                            string s        = book.Identifier;
                            var    index    = s.LastIndexOf("/");
                            string bookName = s.Substring(index + 1);
                            string path     = s.Substring(0, index);
                            var    url      = Environment.GetEnvironmentVariable("deploy");

                            url = string.Format(url, path, bookName);
                            using (var client = new HttpClient())
                            {
                                using (var result = await client.GetAsync(url))
                                {
                                    if (result.IsSuccessStatusCode)
                                    {
                                        var bytes = await result.Content.ReadAsByteArrayAsync();

                                        var f = io.Path.Combine("epubs", book.UniqueLink);
                                        io.File.WriteAllBytes(f, bytes);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            book.IsCorrect    = false;
                            book.ErrorMessage = "download :" + ex.Message;
                        }
                    }
                }
                catch (Exception ex)
                {
                    book.ErrorMessage = ex.Message;
                    book.IsCorrect    = false;
                }
                _context.Add(book);
            }
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
示例#3
0
        public async Task <ActionResult> Register([FromServices] QRContext context, string emailUser, string password)
        {
            //TODO: make a better way to register users
            //TODO: use Google / Facebook authentication
            //TODO: email valid
            emailUser = emailUser?.ToLower();
            var hash = getHash(password);

            if (hash.Length > 500)
            {
                hash = hash.Substring(0, 500);
            }

            var user = context.SimpleUser.FirstOrDefault(it => it.Email.ToLower() == emailUser);

            if (user != null)
            {
                if (!user.ConfirmedByEmail)
                {
                    return(Content($"email {emailUser} does exists . Check your email"));
                }

                if (user.Password == hash)
                {
                    await SignUser(user);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(Content("incorrect password. Press back and try again"));
                }
            }
            user          = new SimpleUser();
            user.Email    = emailUser;
            user.Name     = emailUser;
            user.Password = hash;
            context.Add(user);
            await context.SaveChangesAsync();

            var strSalt = Environment.GetEnvironmentVariable("deploy");

            var    hashids = new Hashids(strSalt);
            var    id      = hashids.EncodeLong(user.Iduser);
            string url     = "http://fsq.apphb.com/Home/GeneratedEmail/" + id;
            var    apiKey  = Environment.GetEnvironmentVariable("SendGridKey");

            var client = new SendGridClient(apiKey);
            var from   = new EmailAddress("*****@*****.**", "Ignat Andrei - QR");
            List <EmailAddress> tos = new List <EmailAddress>
            {
                new EmailAddress(emailUser),
                new EmailAddress("*****@*****.**"),
                new EmailAddress("*****@*****.**")
            };

            var subject     = "Confirmati inregistrarea la QR Code Library ";
            var htmlContent = $"Va rog <strong>confirmati </strong> inscrierea la QR Code library apasand <a href='{url}'>{url}</a>. <br />Multumim!";
            var msg         = MailHelper.CreateSingleEmailToMultipleRecipients(from, tos, subject, "", htmlContent, false);
            var response    = await client.SendEmailAsync(msg);

            return(Content("Va rugam verificat emailul( inclusiv spam/ junk) pentru a confirma adresa de email !"));
        }