Exemple #1
0
        public ActionResult Register(RegistViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = null;
                using (BotAppContext db = new BotAppContext())
                {
                    user = db.Users.FirstOrDefault(u => u.Login == model.Login);
                }
                if (user == null)
                {
                    // создаем нового пользователя
                    using (BotAppContext db = new BotAppContext())
                    {
                        db.Users.Add(new User {
                            Login = model.Login, Password = model.Password, Name = model.UserName, RoleId = 2
                        });
                        db.SaveChanges();

                        user = db.Users.Where(u => u.Login == model.Login && u.Password == model.Password).FirstOrDefault();
                    }
                    // если пользовател успешно добавлен в БД
                    if (user != null)
                    {
                        FormsAuthentication.SetAuthCookie(model.Login, true);
                        return(RedirectToAction("AddToken", "LongPollServer"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Пользователь с таким логином уже существует");
                }
            }
            return(View(model));
        }
Exemple #2
0
        static void Main()
        {
            if (File.Exists(BotAppContext.IconFileName))
            {
                if (!SingleInstance.Start())
                {
                    return;
                }
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                try
                {
                    var applicationContext = new BotAppContext();
                    Application.Run(applicationContext);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Program Terminated Unexpectedly",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);

                    Console.WriteLine(ex.Message + " " + ex.StackTrace);
                }
                SingleInstance.Stop();
            }
            else
            {
                MessageBox.Show("No program icon");
            }
        }
Exemple #3
0
 public ActionResult Login(LoginViewModel model)
 {
     if (ModelState.IsValid)
     {
         // поиск пользователя в бд
         User user = null;
         using (BotAppContext db = new BotAppContext())
         {
             user = db.Users.FirstOrDefault(u => u.Login == model.Login && u.Password == model.Password);
         }
         if (user != null)
         {
             FormsAuthentication.SetAuthCookie(model.Login, true);
             return(RedirectToAction("AddToken", "LongPollServer"));
         }
         else
         {
             ModelState.AddModelError("", "Поьзователя с таким логином и паролем нет в базе");
         }
     }
     return(View(model));
 }
Exemple #4
0
 public PaymentsController(BotAppContext context)
 {
     _context = context;
 }