示例#1
0
        public ActionResult Register(RegistrationModel model)
        {
            LogManager logManager = new LogManager(db);
            if (ModelState.IsValid)
            {

                UserManager userManger = new UserManager(db);
                if (!userManger.IsLoginNameExist(model))
                {
                    userManger.createNewUser(model);
                    //FormsAuthentication.SetAuthCookie(model.UserName, false);
                    logManager.LogSuccessfulRegistration(model.UserName);
                    InsertMessage message = new InsertMessage();

                    // passing message to control about seccussfull registration
                    message.MessageText = "Registered user: "******" successfully. Now you can Log In.";
                    TempData["message"] = message;

                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    logManager.LogUnSuccessfulRegistration(model.UserName);
                    ModelState.AddModelError("", "Username already exists");
                }

            }
            logManager.LogUnSuccessfulRegistration(model.UserName);
            return View();
        }
示例#2
0
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Position,Email,PhoneNumber")] ContactModel contactModel,
            HttpPostedFileBase upload)
        {
            LogManager logManager = new LogManager(db);
            if (ModelState.IsValid)
            {
                // check if image was uploaded
                if(upload != null && upload.ContentLength > 0 ){
                    logManager.LogFileUploadEvent(upload.FileName);
                    var avatar = new File
                    {
                        FileName = System.IO.Path.GetFileName(upload.FileName),
                        FileType = FileType.Avatar,
                        ContentType = upload.ContentType
                    };
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        avatar.Content = reader.ReadBytes(upload.ContentLength);
                    }
                    contactModel.Files = new List<File> { avatar };
                }
                db.Contacts.Add(contactModel);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(contactModel);
        }
示例#3
0
        // Using return Url, to take user back to page, where he wanted to go
        public ActionResult Index(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                LogManager logManager = new LogManager(db);
                UserManager userManger = new UserManager(db);
                string password = userManger.GetUserPassword(model);
                if (string.IsNullOrEmpty(password))
                {
                    ModelState.AddModelError("", "The user login or password provided is incorrect.");
                }
                else if (model.Password.Equals(password))
                {
                    FormsAuthentication.SetAuthCookie(model.Username, false);
                    logManager.LogSuccessfulLogin(model.Username);

                    // redirects the user to page, where he wanted to go
                    if (!string.IsNullOrWhiteSpace(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }

                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    logManager.LogUnSuccessfulLogin(model.Username);
                    ModelState.AddModelError("", "The password provided is incorrect.");
                }

                logManager.LogUnSuccessfulLogin(model.Username);
                ModelState.AddModelError("", "Bad login attempt");
            }

            return View(model);
        }