예제 #1
0
        //----------------------------
        //      Send Receipt Email
        //----------------------------
        private static void SendReceiptEmail(string toEmail, int?amount, string name, int?tripId)
        {
            ApplicationDbContext db = new ApplicationDbContext();

            Trip trip = db.Trips
                        .SingleOrDefault(t => t.Id == tripId);

            DateTime date       = DateTime.Today;
            string   dateFormat = "MMM d yyyy";
            string   today      = date.ToString(dateFormat);

            StuProfile       student = trip.Student;
            StudentViewModel stuVM   = new StudentViewModel(student);

            string picPath = stuVM.Upload.FilePath;

            string msg = "Thank you for helping send "
                         + stuVM.Student.FirstName + " to " + trip.DestinationCountry + "! </br></br>"
                         + "You donated $" + amount + " on " + today + ".";

            string body = "<table><tr><td style=\"padding: 20px\"><img src=\"" + picPath
                          + "\" style = \"width: 150px; height: 150px; border-radius: 50%\" ></td >"
                          + "<td style=\"padding: 20px; text-align: left\">" + msg + "</td></tr></table>";

            string fromEmail = ConfigurationManager.AppSettings["SendEmailsFrom"];

            string subj = "Donation Receipt from SendMe!";

            MailHelper.Execute(body, name, toEmail, "SendMe!", fromEmail, subj);
        }
예제 #2
0
        public ActionResult SendThankYou(int?donId, int?stuId, string thxMsg)
        {
            ApplicationDbContext db = new ApplicationDbContext();

            Donation         donation = db.Donations.Find(donId);
            Trip             trip     = db.Trips.Find(donation.TripId);
            StuProfile       stuProf  = db.StuProfiles.Find(stuId);
            StudentViewModel student  = new StudentViewModel(stuProf);
            string           picPath  = student.Upload.FilePath;

            string subj = "Thank you for helping send me to " + trip.Destination + "!";

            string body = "<table><tr><td style=\"padding: 20px\"><img src=\"" + picPath
                          + "\" style = \"width: 150px; height: 150px; border-radius: 50%\" ></td >"
                          + "<td style=\"padding: 20px: text-align: left\">" + thxMsg + "</td></tr></table>";

            string fromEmail = ConfigurationManager.AppSettings["SendEmailsFrom"];

            MailHelper.Execute(body, donation.Donor.Name, donation.Donor.Email, student.Student.FirstName, student.Student.User.Email, subj);

            donation.HaveThanked     = true;
            db.Entry(donation).State = EntityState.Modified;
            db.SaveChanges();

            string returnUrl = "../send/" + student.User.UserName;

            return(RedirectToAction(returnUrl));
        }
예제 #3
0
        public ActionResult Index(string username)
        {
            StuProfile student = db.StuProfiles
                                 .Where(sp => sp.User.UserName == username)
                                 .FirstOrDefault();

            if (user == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            StudentViewModel studentVM = new StudentViewModel(student);

            return(View(studentVM));
        }
예제 #4
0
        //
        // GET: /Manage/Index
        public async Task <ActionResult> Index(ManageMessageId?message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();

            ViewBag.RefId     = userId;
            ViewBag.Type      = "Student";
            ViewBag.ReturnUrl = "../Manage";
            ViewBag.ImgPath   = GetExistingImage("ProfPic", ViewBag.RefId);

            var indexVM = new IndexViewModel
            {
                HasPassword       = HasPassword(),
                PhoneNumber       = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor         = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins            = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };

            StuProfile profile = db.StuProfiles
                                 .Where(sp => sp.UserId == userId)
                                 .FirstOrDefault();

            School school = db.Schools.Find(profile.SchoolId);

            ViewBag.AdminSchool = school;
            ViewBag.CoverPath   = GetExistingImage("schCover", school.Id.ToString());
            ViewBag.LogoPath    = GetExistingImage("schLogo", school.Id.ToString());

            return(View(new Tuple <StuProfile, IndexViewModel>(profile, indexVM)));
        }
예제 #5
0
        public ActionResult UpdateProfile([Bind(Prefix = "Item1")] StuProfile model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            string userId = User.Identity.GetUserId();

            StuProfile profile = db.StuProfiles
                                 .Where(sp => sp.UserId == userId)
                                 .FirstOrDefault();

            if (model.FirstName != null)
            {
                profile.FirstName = model.FirstName;
            }
            if (model.LastName != null)
            {
                profile.LastName = model.LastName;
            }
            if (model.Speciality != null)
            {
                profile.Speciality = model.Speciality;
            }
            if (model.Year != null)
            {
                profile.Year = model.Year;
            }
            if (model.Bio != null)
            {
                profile.Bio = model.Bio;
            }

            db.Entry(profile).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Index", "Manage"));
        }
예제 #6
0
        public StuLoginResp Login([FromBody] StuLoginReq req)
        {
            StuLoginResp resp = new StuLoginResp();

            try
            {
                if (!Fun.ExistStuID(req.stu_id))
                {
                    resp.msg    = "账号密码错误";
                    resp.status = -1;
                }
                else
                {
                    var result = Fun.GetSqlConn().Query($"select * from student where stu_id = '{req.stu_id}'");
                    var stu    = result.Single();
                    if (Fun.GetMD5String(req.pwd) == stu.pwd)
                    {
                        resp.msg    = "登陆成功";
                        resp.status = 0;
                        StuProfile sp = new StuProfile(stu.id, stu.stu_id, stu.name, stu.nick_name, stu.gender, stu.email, stu.is_active);
                        resp.data = sp;
                    }
                    else
                    {
                        resp.msg    = "账号密码错误";
                        resp.status = -1;
                    }
                }
            }
            catch (Exception ex)
            {
                resp.msg    = "未知错误" + ex.ToString();
                resp.status = -2;
                Console.WriteLine(resp.msg);
            }

            return(resp);
        }
예제 #7
0
        public ActionResult Index(string username, int?donationId, string paymentMsg, string email)
        {
            StuProfile student = db.StuProfiles
                                 .Where(sp => sp.User.UserName == username)
                                 .FirstOrDefault();
            StudentViewModel studentVM = new StudentViewModel(student);

            if (student == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            ViewBag.CurrentTotal = 0;

            if (studentVM.ActiveTrip != null)
            {
                ViewBag.TargetAmount = studentVM.ActiveTrip.Trip.TargetAmnt;
                if (studentVM.ActiveTrip.Donations.Count() != 0)
                {
                    foreach (var donation in studentVM.ActiveTrip.Donations)
                    {
                        ViewBag.CurrentTotal += (double)donation.Amount;
                    }
                }

                if (ViewBag.TargetAmount <= ViewBag.CurrentTotal)
                {
                    ViewBag.CurrentTotal = ViewBag.TargetAmount;
                }
            }
            else
            {
                ViewBag.Action = "Create";
            }

            if (donationId != null)
            {
                var donationModify =
                    from donation in db.Donations
                    .Where(d => d.Id == donationId)
                    select donation;

                foreach (Donation donation in donationModify)
                {
                    donation.HaveThanked = true;
                }
                db.SaveChanges();
            }

            ViewBag.UserName = username;

            if (paymentMsg == "Payment Successful")
            {
                ViewBag.PaymentMsg = $"{paymentMsg}! An electronic receipt has been sent to {email}.";
            }
            else if (paymentMsg == null)
            {
                ViewBag.PaymentMsg = null;
            }
            else
            {
                ViewBag.PaymentMsg = $"There was a problem: {paymentMsg}";
            }
            ViewBag.Email = email;

            return(View(studentVM));
        }
예제 #8
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            string userid;

            try
            {
                userid = UserManager.FindByEmail(model.Email).Id;
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }

            //If user email has not been verified return view with message
            if (userid != null && !UserManager.IsEmailConfirmed(userid))
            {
                ViewBag.NotConfirmed = "A confirmation email was sent to " + model.Email
                                       + " but the email has not yet been confirmed. Please look for the confirmation"
                                       + " email in your inbox and click the provided link to confirm and log in.";
                ModelState.Clear();
                return(View());
            }

            //Get Existing UserName
            string username = UserManager.FindByEmail(model.Email).UserName;

            //Update username only if it doesn't match the custom username conventions
            if (username.Contains('@'))
            {
                username = UserHelpers.CreateUserName(model.Email);
            }
            ;

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(username, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                //If no returnUrl when user logged in, send them to their profile
                //If user is Admin, send to school profile

                StuProfile profile = db.StuProfiles
                                     .Where(sp => sp.UserId == userid)
                                     .FirstOrDefault();

                if (returnUrl == null && profile.FirstName != "Admin")
                {
                    returnUrl = "/send/" + username;
                }
                else if (returnUrl == null && profile.FirstName == "Admin")
                {
                    string schId = profile.SchoolId.ToString();
                    returnUrl = "/school/" + schId;
                }

                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
예제 #9
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.ContainsKey("Email"))
            {
                ModelState["Email"].Errors.Clear();
            }

            //-----------------------------------------------
            //            Verify Domain of Email
            //-----------------------------------------------
            string schDomain = db.Schools
                               .Where(s => s.Id == model.SchoolId)
                               .Select(s => s.EmailDomain)
                               .Single();

            if (!model.Email.Contains(schDomain))
            {
                ModelState.AddModelError("Email", "That domain is not approved by your school. "
                                         + "Please check for typos and ensure that you have selected the correct school. "
                                         + "If you believe you received this message in error, please contact your administrator.");

                ViewBag.Schools = new SchoolCollection();

                return(View(model));
            }

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //---------------------------------------------------
                    //          Verify Admin Key and Add to Role
                    //---------------------------------------------------
                    string adminKey = WebConfigurationManager.AppSettings["AdminKey"];
                    bool   isAdmin  = false;
                    if (model.AdminKey != null && model.AdminKey == adminKey)
                    {
                        var result1 = UserManager.AddToRole(user.Id, "Admin");
                        isAdmin = true;
                    }

                    //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    //---------------------------------------------------
                    //          Create username for custom url
                    //---------------------------------------------------
                    user.UserName = UserHelpers.CreateUserName(model.Email);

                    db.Entry(user).State = EntityState.Modified;
                    db.SaveChanges();

                    //---------------------------------------------------
                    //   Create Student Profile & Add Placeholder Pic
                    //---------------------------------------------------

                    StuProfile stuProfile = new StuProfile(user, model.SchoolId);
                    if (isAdmin)
                    {
                        stuProfile.FirstName = "Admin";
                        stuProfile.LastName  = "Admin";
                    }
                    db.StuProfiles.Add(stuProfile);

                    Upload placeholder = new Upload
                    {
                        File    = "sm03162017profpic-placeholder.jpg",
                        RefId   = user.Id,
                        TypeRef = "ProfPic"
                    };
                    db.Uploads.Add(placeholder);

                    db.SaveChanges();


                    //---------------------------------------------------
                    //          Send Confirmation Email
                    //---------------------------------------------------
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var callbackUrl = Url.Action("ConfirmEmail", "Account",
                                                 new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    string body = MailHelper.PopulateBody("Please confirm your account by clicking <a href=\""
                                                          + callbackUrl + "\">here</a>");
                    await UserManager.SendEmailAsync(user.Id, "Confirm your SendMe! account", body);

                    ViewBag.SentConf = "A confirmation email was sent to " + model.Email
                                       + ". Please look for the confirmation email in your inbox and click the provided link to confirm and log in.";

                    ModelState.Clear();

                    ViewBag.Schools = new SchoolCollection();

                    return(View(model));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            ViewBag.Schools = new SchoolCollection();
            return(View(model));
        }