Exemplo n.º 1
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                AnaWeenEntities entities = new AnaWeenEntities();             
                if (entities.Members.Any(m => (model.UserName == m.Login || model.UserName == m.Mail) && m.Password == model.Password))
                {
                    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", new { login = model.UserName });
                    }
                }
                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.º 2
0
        public string Send(string thought, int top, int left, int level)
        {
            AnaWeenEntities entities = new AnaWeenEntities();
            var user = entities.Members.First(u => u.Login == User.Identity.Name || u.Mail == User.Identity.Name);
            if (user != null)
            {
                var lexs = thought.Split(' ').Where(l => l.Length > 0 && l[0] == '#');
                var newThought = new Thought() { Text = thought, Top = top, left = left, Level = level };
                foreach (var lex in lexs)
                {
                    if (!entities.Lexicons.Any(l => l.Value == lex))
                    {
                        newThought.Lexicon.Add(new Lexicon() { Value = lex });
                    }
                    else
                    {
                        newThought.Lexicon.Add(entities.Lexicons.FirstOrDefault(l => l.Value == lex));
                    }
                }
                user.Thoughts.Add(newThought);
                entities.SaveChanges();
                return thought;
            }
            else
            {
                return "Error";
            }

        }
Exemplo n.º 3
0
 public string UpdateLevel(int id, int level)
 {
     AnaWeenEntities entities = new AnaWeenEntities();
     var fekra = entities.Thoughts.FirstOrDefault(f => f.Id == id);
     fekra.Level = level;
     entities.SaveChanges();
     return "lux";
 }
Exemplo n.º 4
0
 public string UpdatePosition(int id, int top, int left)
 {
     AnaWeenEntities entities = new AnaWeenEntities();
     var fekra = entities.Thoughts.FirstOrDefault(f => f.Id == id);
     fekra.Top = top;
     fekra.left = left;
     entities.SaveChanges();
     return "lux";
 }
Exemplo n.º 5
0
 public void UpdateFekra(int id,string thought )
 {
     AnaWeenEntities entities = new AnaWeenEntities();
     var user = entities.Members.First(u => u.Login == User.Identity.Name || u.Mail == User.Identity.Name);
     if (user != null)
     {
         var fekra = user.Thoughts.FirstOrDefault(t => t.Id == id);
         fekra.Text = thought;
         entities.SaveChanges();               
     }
 
 }
Exemplo n.º 6
0
 public ActionResult Index(string login)
 {
     AnaWeenEntities entities = new AnaWeenEntities();
     var user = entities.Members.First(u => u.Login == login || u.Mail == login);
     if (!string.IsNullOrEmpty(User.Identity.Name))
     {
         return View(user);
     }
     else
     {
         Member profile = new Member();
         profile.Thoughts=user.Thoughts.Where(t => t.Visibility == true) as EntityCollection<Thought>;                
         return View(profile);
     }
 }
Exemplo n.º 7
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                AnaWeenEntities entities = new AnaWeenEntities();
                entities.Members.AddObject(new Member() { Login = model.UserName, Password = model.Password, Mail = model.Email });
                try
                {
                    entities.SaveChanges();
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    return RedirectToAction("Index", "Home", new { login = model.UserName });
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", e.Message);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 8
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    AnaWeenEntities entities = new AnaWeenEntities();
                    var user = entities.Members.FirstOrDefault(u => u.Login == User.Identity.Name);
                    //MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
                    if (user != null)
                    {
                        user.Password = model.NewPassword;
                        entities.SaveChanges();
                        return RedirectToAction("ChangePasswordSuccess");
                    }
                    // changePasswordSucceeded = user.Password (model.OldPassword, model.NewPassword);
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 9
0
 public string UpdateVisibility(int id, bool visibility)
 {
     AnaWeenEntities entities = new AnaWeenEntities();
     var fekra = entities.Thoughts.FirstOrDefault(f => f.Id == id);
     fekra.Visibility = visibility;
     entities.SaveChanges();
     return "lux";
 }