Exemplo n.º 1
0
        public ActionResult ForgottenPassword(LogOnModel logOnModel)
        {
            try
            {

                var currentUser = Membership.GetUser(logOnModel.UserName);

                if (currentUser != null)
                {

                    var password = currentUser.ResetPassword();

                    var emailSender = new EMail();

                    var body = string.Format("Hi {0}!\r\nYour new password is {1}", currentUser.UserName, password);

                    var mailMessage = new MailMessage("*****@*****.**", currentUser.Email, "ArtSite details",
                                                              body);
                    var result = emailSender.SendEmailAsync(mailMessage);

                    return RedirectToAction("PassWordSent", new { emailAddress = currentUser.Email });

                }
                else
                {
                    ModelState.AddModelError("", string.Format("'{0}' is not registered", logOnModel.Email));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.ToString());

            }
            return View();
        }
Exemplo n.º 2
0
        private LogOnModel CreateUser(string name, string email)
        {
            name = name.ToLower();
            var user = new LogOnModel()
            {
                UserName = name,
                Password = "******",
                Email = email,
                Permissions = "0",
                Active = false
            };

            _userDal.Enitities.Add(user);
            try
            {
                _userDal.SaveChanges();
            }
            catch (Exception ex)
            {
                var u = _userDal.Enitities.FirstOrDefault(x => x.UserName == name);
                if (u != null)
                {
                    Logger.Error("user already exists in CreateUser", ex);
                }
                else
                    throw;

            }

            return user;
        }
Exemplo n.º 3
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                //if (ValidateUser(model.UserName, model.Password))
                {
                    //check that user has logonModel record too!
                    var logOnModel = UserDal.AllUsers.FirstOrDefault(x => x.UserName == model.UserName);

                    if (logOnModel == null)
                    {
                        CreateUser(model.UserName, model.Email);
                    }
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 4
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                HttpPostedFile hpf = context.Request.Files["file"];
               // if (hpf.ContentLength > 0 && FileIsPicture(hpf))
                if (hpf.ContentLength > 0)
                {

                    int chunk = context.Request["chunk"] != null ? int.Parse(context.Request["chunk"]) : 0;
                    int totalChunks = context.Request["chunks"] != null ? int.Parse(context.Request["chunks"]) : 1;

                    string fileName = context.Request["name"] ?? string.Empty;

                    string filePath = context.Server.MapPath("MyFiles");

                    using (var fs = new FileStream(Path.Combine(filePath, fileName), chunk == 0 ? FileMode.Create : FileMode.Append))
                    {
                        var buffer = new byte[hpf.InputStream.Length];
                        hpf.InputStream.Read(buffer, 0, buffer.Length);
                        fs.Write(buffer, 0, buffer.Length);
                    }

                    //only do this part when chunk complete
                    if (chunk == totalChunks-1)
                    {
                        byte[] bufferFinal = ImageProcessor.ImageAsByteArray(Path.Combine(filePath, fileName),
                                                                             System.Drawing.Imaging.ImageFormat.Jpeg);

                        using (ArtGalleryDBContext db = new ArtGalleryDBContext())
                        {
                            var currentUser =  UserDal.AllUsers.FirstOrDefault(x => x.UserName.ToLower() == context.User.Identity.Name.ToLower());
                            if (currentUser == null)
                            {
                                currentUser = new LogOnModel()
                                {
                                    UserId = 99999,
                                    UserName = context.User.Identity.Name
                                };
                                Logger.Info("user could not be found for upload", null);
                            }
                            var picture = new PictureItem
                                                      {
                                                          ImageT = bufferFinal,
                                                          Created = DateTime.Now,
                                                          Artist = currentUser.UserName,
                                                          UserId = currentUser.UserId
                                                      };

                            IPictureDal pictureDal = new PictureDal(db);
                            //saveto db
                            pictureDal.Enitities.Add(picture);
                            pictureDal.SaveChanges();

                        }

                    }

                }
                //save any old file to myFiles...
                //else
                //{
                //    string filePath = context.Server.MapPath("MyFiles") + "\\" +
                //                        System.IO.Path.GetFileName(hpf.FileName);

                //    hpf.SaveAs(filePath);
                //}

                context.Response.Write("1");
            }
            catch (Exception ex)
            {
                Logger.Error("In upload.ashx", ex);
            }
        }
        public static List<PictureItemNoBufferData> GetImagesFromDbMin(LogOnModel user, string theme)
        {
            using (var db = (ArtGalleryDBContext)DependencyResolver.Current.GetService<DbContext>())
            {
                var userId = user != null ? user.UserId : -1;

                var pictureDal = new PictureDal(db);

                var model = pictureDal.Enitities.Where(x => x.UserId == userId);

                if (theme != null)
                    model = theme == string.Empty ? model.Where(x => x.Theme == string.Empty || x.Theme == null) : model.Where(x => x.Theme.ToLower().Contains(theme.ToLower()));

                var query = from c in model
                            select new PictureItemNoBufferData()
                            {
                                Artist = c.Artist,
                                Created = c.Created,
                                ID = c.ID,
                                Media = c.Media,
                                Price = c.Price,
                                Size = c.Size,
                                Theme = c.Theme,
                                Title = c.Title,
                                UserId = c.UserId,
                                DisplayOrder = c.DisplayOrder

                            };

                return query.OrderBy(x => x.DisplayOrder ?? 9999).ToList();
            }
        }
 public static List<PictureItemNoBufferData> GetImagesFromDbMin(LogOnModel user)
 {
     return GetImagesFromDbMin(user, null);
 }