Exemplo n.º 1
0
        public StudentLogin Check(String refToken)
        {
            var output = new StudentLogin();
            
            using (var client = new SqlConnection(SqlConn))
            {

                using (var command = new SqlCommand())
                {
                    command.Connection = client;
                    command.CommandText = $"select indexnumber, reftoken from student where reftoken = '{refToken}'";

                    client.Open();
                    var dr = command.ExecuteReader();
                    while (dr.Read())
                    {
                        output = (new StudentLogin
                        {
                            IndexNumber = dr["IndexNumber"].ToString(),
                            refToken = dr["refToken"].ToString()
                        }); ;

                    }

                }
            }
            return output;
        }
Exemplo n.º 2
0
    public static void AddToReview(int pointId)
    {
        //Server.GetInstance().Submit(pointId,false);
        ReviewRecord reviewRecord;

        if (currentRole.reviews.ContainsKey(pointId))
        {
            reviewRecord        = currentRole.reviews[pointId];
            reviewRecord.times += 1;
        }
        else
        {
            reviewRecord         = new ReviewRecord();
            reviewRecord.times   = 1;
            reviewRecord.pointId = pointId;
            currentRole.reviews.Add(pointId, reviewRecord);
        }
        reviewRecord.ticks = GetReviewTicks(reviewRecord.times);

        reviewRecord.ticks = GetReviewTicks(reviewRecord.times);
        Review review = new Review(Role.currentRole.id, Role.sn, reviewRecord);
        string msg    = review.id + "|" + JsonMapper.ToJson(review);

        Debug.LogError(msg);
        (StudentLogin.GetInstance()).SendMsg(msg);
    }
Exemplo n.º 3
0
        public ActionResult Login(string studentID, string studentPass)
        {
            string u = studentID;
            string p = studentPass;

            if (studentID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StudentLogin studentLogin = db.StudentLogins.Find(Convert.ToInt32(studentID));

            if (studentLogin == null)
            {
                ViewBag.LoginSuccess = "Please Retry, please type again.";
            }
            else
            {
                if (studentPass == studentLogin.student_pwd)
                {
                    ViewBag.LoginSuccess = "Success";
                    System.Web.HttpContext.Current.Session["sv_studentLogin"] = Convert.ToInt32(studentID);
                    return(RedirectToAction("Index", "StudentPortal", null));
                }
                else
                {
                    ViewBag.LoginSuccess = "Failed";
                }
            }


            return(View());
        }
Exemplo n.º 4
0
 protected void btnLogin_Click(object sender, EventArgs e)
 {
     tbLogin.Text.ToUpper();
     validateLogin.Visible    = false;
     validatePassword.Visible = false;
     if (string.IsNullOrEmpty(tbLogin.Text) || string.IsNullOrEmpty(tbPassword.Text))
     {
         if (string.IsNullOrEmpty(tbLogin.Text))
         {
             validateLogin.Visible = true;
         }
         if (string.IsNullOrEmpty(tbPassword.Text))
         {
             validatePassword.Visible = true;
         }
     }
     else
     {
         StudentLogin    stuObj = new StudentLogin();
         StudentLoginDAO stuDao = new StudentLoginDAO();
         stuObj = stuDao.getStudentById(tbLogin.Text, tbPassword.Text);
         if (stuObj == null)
         {
             lblErrorMessage.Visible = true;
         }
         else
         {
             Session["AdminNo"] = stuObj.AdminNo;
             Session["role"]    = stuObj.Year;
             Response.Redirect("TripDetails.aspx");
             string roleformasterpage = Session["role"].ToString();
         }
     }
 }
Exemplo n.º 5
0
        public IActionResult StudentIndex(StudentLogin studentLogin)
        {
            if (ModelState.IsValid)
            {
                var result = _context.NewRegisteredStudent.Where(x => x.UserName == studentLogin.UserName).Single();     //if null ? or does not exist
                if (VerifyPassword(result.Password, studentLogin.Password))
                {
                    return(View("StudentIndex", result));
                }

                return(View("StudentLogin", studentLogin));
            }
            return(View("StudentLogin", studentLogin));

            //while registration make sure the name does not exist


            //must do username
            //check in the internet how to implement login
            //send the new password to verifyPass
            //if true then check the username


            // return View(await _context.NewRegisteredStudent.ToListAsync());
        }
Exemplo n.º 6
0
        public ActionResult Token(StudentLogin student)
        {
            var identity = GetIdentity(student.login, student.password);

            if (identity == null)
            {
                return(BadRequest(new { errorText = "Invalid username or password." }));
            }

            var now = DateTime.UtcNow;
            // создаем JWT-токен
            var jwt = new JwtSecurityToken(
                issuer: AuthOptions.ISSUER,
                audience: AuthOptions.AUDIENCE,
                notBefore: now,
                claims: identity.Claims,
                expires: now.Add(TimeSpan.FromMinutes(AuthOptions.LIFETIME)),
                signingCredentials: new SigningCredentials(AuthOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256));
            var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt);

            var response = new
            {
                access_token = encodedJwt,
                username     = identity.Name,
                id           = int.Parse(identity.FindFirst("studentId").Value)
            };

            return(Ok(JsonConvert.SerializeObject(response)));
        }
        public ActionResult Index(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var dao    = new StudentDao();
                var result = dao.IsValid(model.username, Encryptor.MD5Hash(model.password));
                if (result)
                {
                    var admin         = dao.GetByUserName(model.username);
                    var studenSession = new StudentLogin();

                    studenSession.id_student     = admin.id_student;
                    studenSession.student_name   = admin.student_name;
                    studenSession.student_avatar = admin.student_avatar;
                    Session.Add(CommonConstants.STUDENT_SESSION, studenSession);
                    dao.UpdateLastLogin(studenSession.id_student, GetIPAddress(), GetUserEnvironment());
                    dao.UpdateLastSeen("Trang chủ", Url.Action("Index"), studenSession.id_student);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Sai thông tin đăng nhập.");
                }
            }
            return(View(model));
        }
Exemplo n.º 8
0
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var dao    = new StudentDAO();
                var result = dao.Login(model.Email, Encryptor.MD5Hash(model.Password));
                if (result == 1)
                {
                    var student        = dao.GetById(model.Email);
                    var studentSession = new StudentLogin();
                    studentSession.Email = student.Email;
                    studentSession.ID    = student.Id;

                    Session.Add(Common_Constants.STUDENT_SESSION, studentSession);
                    return(RedirectToAction("Index", "Home"));
                }
                else if (result == 0)
                {
                    ModelState.AddModelError("", "Account is invalid");
                }
                else if (result == -1)
                {
                    ModelState.AddModelError("", "Account was locked");
                }
                else if (result == -2)
                {
                    ModelState.AddModelError("", "Email or Password is incorrect");
                }
                else
                {
                    ModelState.AddModelError("", "Login false.");
                }
            }
            return(View("Index"));
        }
Exemplo n.º 9
0
 public static void AddToReviewByDialog(int sentenceId)
 {
     Dictionary <int, Point> .Enumerator iter = Point.points.GetEnumerator();
     while (iter.MoveNext())
     {
         if (iter.Current.Value.sentenceId == sentenceId)
         {
             ReviewRecord reviewRecord;
             if (currentRole.reviews.ContainsKey(iter.Current.Value.id))
             {
                 reviewRecord        = currentRole.reviews[iter.Current.Value.id];
                 reviewRecord.times += 1;
             }
             else
             {
                 reviewRecord         = new ReviewRecord();
                 reviewRecord.times   = 1;
                 reviewRecord.pointId = iter.Current.Value.id;
                 currentRole.reviews.Add(reviewRecord.pointId, reviewRecord);
             }
             //Server.GetInstance().Submit(iter.Current.Value.id,Role.currentRole.isReview);
             reviewRecord.ticks = GetReviewTicks(reviewRecord.times);
             Review review = new Review(Role.currentRole.id, Role.sn, reviewRecord);
             string msg    = review.id + "|" + JsonMapper.ToJson(review);
             Debug.LogError(msg);
             (StudentLogin.GetInstance()).SendMsg(msg);
         }
     }
 }
Exemplo n.º 10
0
 public ActionResult Login(StudentLogin model)
 {
     if (model.Username == "test" && model.Password == "123")
     {
         return(RedirectToAction("Index", "Student"));
     }
     return(View());
 }
Exemplo n.º 11
0
        public ActionResult DeleteConfirmed(int id)
        {
            StudentLogin studentLogin = db.StudentLogins.Find(id);

            db.StudentLogins.Remove(studentLogin);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 12
0
 public SendQuizInfo(StudentLogin student, List <StoredQuestions> sq, List <CompletedQuestion> cq, StoredQuizzes storedQuizzes)
 {
     //The student, storedquestions that they have answered, their completed question and the quiz are passed into the sub and then made global by this sub.
     InitializeComponent();
     Student       = student;
     SQ            = sq;
     CQ            = cq;
     storedquizzes = storedQuizzes;
 }
        public LoginResponse CreateStudentLogin(StudentLogin studentLoginObj)
        {
            _schoolDBContext.StudentLogins.Add(studentLoginObj);
            _schoolDBContext.SaveChanges();

            return(new LoginResponse {
                Status = "Success", Message = "Account sucessfully generated!"
            });
        }
        public ActionResult Login(string staffID, string staffPass)
        {
            string u = staffID;
            string p = staffPass;

            if (staffID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StaffLogin   staffLogin   = db.StaffLogins.Find(Convert.ToInt32(staffID));
            Staff        staff        = db.Staffs.Find(Convert.ToInt32(staffID));
            StudentLogin studentLogin = db.StudentLogins.Find(Convert.ToInt32(staffID));

            if (studentLogin != null)
            {
                ViewBag.Message = "Please log in using the Student Login page.";
                return(View());
            }
            else
            {
                if (staffLogin == null)
                {
                    ViewBag.LoginSuccess = "Please Retry, please type again.";
                }
                else
                {
                    if (staff.access_level == 1)
                    {
                        if (staffPass == staffLogin.staff_pwd)
                        {
                            ViewBag.LoginSuccess = "Success";
                            System.Web.HttpContext.Current.Session["sv_staffLogin"] = Convert.ToInt32(staffID);
                            return(RedirectToAction("Index", "StaffPortal", null));
                        }
                        else
                        {
                            ViewBag.LoginSuccess = "Failed";
                        }
                    }
                    else
                    {
                        if (staffPass == staffLogin.staff_pwd)
                        {
                            ViewBag.LoginSuccess = "Success";
                            System.Web.HttpContext.Current.Session["sv_staffLogin"] = Convert.ToInt32(staffID);
                            return(RedirectToAction("Index", "TeacherPortal", null));
                        }
                        else
                        {
                            ViewBag.LoginSuccess = "Failed";
                        }
                    }
                }
            }

            return(View());
        }
Exemplo n.º 15
0
 public ActionResult Edit([Bind(Include = "student_id,student_pwd")] StudentLogin studentLogin)
 {
     if (ModelState.IsValid)
     {
         db.Entry(studentLogin).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.student_id = new SelectList(db.Students, "StudentID", "Fname", studentLogin.student_id);
     return(View(studentLogin));
 }
Exemplo n.º 16
0
 public ActionResult Edit([Bind(Include = "StudentLoginID,StudentID,UserName,Password,Mail")] StudentLogin studentLogin)
 {
     if (ModelState.IsValid)
     {
         db.Entry(studentLogin).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StudentID = new SelectList(db.Students, "StudentID", "FullName", studentLogin.StudentID);
     return(View(studentLogin));
 }
Exemplo n.º 17
0
        public event Action <StartQuizForm, StudentLogin, StoredQuizzes, List <StoredQuestions>, List <StoredQuizQuestions>, List <CompletedQuestion> > CompletedQuiz; //This event is used to return the values of the completed quiz to the stats form when this form is closed

        public StartQuizForm(StudentLogin student, StoredQuizzes sQuiz, List <StoredQuestions> sQuestions, List <StoredQuizQuestions> storedQQuestions, CompletedQuiz cQuiz, List <CompletedQuestion> compQuestion)
        {
            InitializeComponent();
            //Parameters are assigned to the global variables
            Student             = student;
            SQuiz               = sQuiz;
            storedQuestions     = sQuestions;
            storedQuizQuestions = storedQQuestions;
            completedQuiz       = cQuiz;
            completedQuestion   = compQuestion;
        }
Exemplo n.º 18
0
        public ActionResult Create([Bind(Include = "student_id,student_pwd")] StudentLogin studentLogin)
        {
            if (ModelState.IsValid)
            {
                db.StudentLogins.Add(studentLogin);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.student_id = new SelectList(db.Students, "StudentID", "Fname", studentLogin.student_id);
            return(View(studentLogin));
        }
Exemplo n.º 19
0
        public ActionResult Login(StudentLogin login, string ReturnUrl = "")
        {
            string message = "";

            using (StudentContext studentContext = new StudentContext())
            {
                var student = studentContext.students.Where(s => s.EmailId == login.EmailId).FirstOrDefault();
                if (student != null)
                {
                    if (Cryptography.ValidatePasswords(student.Password, login.Password))
                    {
                        if (student.IsEmailVerified == true)
                        {
                            // The Remember me cookie
                            int    timeOut   = login.RememberMe ? 525600 : 5;    //(365d * 24h * 60m )
                            var    ticket    = new FormsAuthenticationTicket(login.EmailId, login.RememberMe, timeOut);
                            string encrypted = FormsAuthentication.Encrypt(ticket);
                            var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                            cookie.Expires  = DateTime.Now.AddMinutes(timeOut);
                            cookie.HttpOnly = true;

                            System.Web.HttpContext.Current.Session["StudentID"] = student.StudentId.ToString();

                            System.Web.HttpContext.Current.Session["StudentName"] = student.LastName.ToString();

                            Response.Cookies.Add(cookie);
                            if (Url.IsLocalUrl(ReturnUrl))
                            {
                                return(Redirect(ReturnUrl));
                            }
                            else
                            {
                                return(RedirectToAction("Index", "Home", student.StudentId));
                            }
                        }
                        else
                        {
                            message = "Email address need to be virified";
                        }
                    }
                    else
                    {
                        message = "Invalid Password";
                    }
                }
                else
                {
                    message = "Invalid User name ";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
Exemplo n.º 20
0
 public ActionResult Login(StudentLogin studentLogin)
 {
     if (ModelState.IsValid && StudentExist(studentLogin.StudentNumber, studentLogin.Password))
     {
         FormsAuthentication.SetAuthCookie(studentLogin.StudentNumber, false);
         return(RedirectToAction("Index", "Student", studentLogin));
     }
     else
     {
         ModelState.AddModelError("", "Invalid Username or Password");
         return(View("Login", studentLogin));
     }
 }
Exemplo n.º 21
0
        // GET: StudentLogins/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StudentLogin studentLogin = db.StudentLogins.Find(id);

            if (studentLogin == null)
            {
                return(HttpNotFound());
            }
            return(View(studentLogin));
        }
        public IActionResult UpdateStudentLogin(int Id, [FromBody] StudentLogin studentLoginObject)
        {
            if (Id < 0)
            {
                BadRequest();
            }

            int result = _studentLoginRepo.UpdateStudentLogin(Id, studentLoginObject);

            if (result == 0)
            {
                return(BadRequest());
            }
            return(Ok());
        }
Exemplo n.º 23
0
        // GET: StudentLogins/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StudentLogin studentLogin = db.StudentLogins.Find(id);

            if (studentLogin == null)
            {
                return(HttpNotFound());
            }
            ViewBag.student_id = new SelectList(db.Students, "StudentID", "Fname", studentLogin.student_id);
            return(View(studentLogin));
        }
Exemplo n.º 24
0
        public bool CheckStudent(StudentLogin student, IHubContext <RoomHub> hubContext)
        {
            //sprawdzić studenta w bazie
            //get RoomId by student.Pin
            Debug.WriteLine("checkstudentprzed");
            var RoomId = "123456";

            hubContext.Groups.AddToGroupAsync(student.ConnectionId, RoomId);
            var room = _roomService.Rooms.FirstOrDefault(x => x.Value.RoomId == RoomId && x.Value.CanJoin == true);

            room.Value.Players.Add(new RoomPlayer {
                ConnectionId = student.ConnectionId, Nick = student.Nick
            });
            Debug.WriteLine("checkstudentpo");
            return(true);
        }
        public IActionResult CreateStudentLogin([FromBody] StudentLogin studentLoginObj)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (studentLoginObj == null)
            {
                return(BadRequest());
            }

            var response = _studentLoginRepo.CreateStudentLogin(studentLoginObj);

            return(Ok(response));
        }
Exemplo n.º 26
0
        public ActionResult Register([Bind(Exclude = "IsEmailVerified,ActivationCode")] StudentLogin studentLogin)
        {
            bool   Status  = false;
            string message = "";

            if (ModelState.IsValid)
            {
                // Email is already Exist
                var isExist = IsEmailExist(studentLogin.Email);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(studentLogin));
                }

                // Generate Activation Code
                studentLogin.ActivationCode = Guid.NewGuid();

                // Password Hashing
                studentLogin.Password        = Crypto.Hash(studentLogin.Password);
                studentLogin.ConfirmPassword = Crypto.Hash(studentLogin.ConfirmPassword);

                studentLogin.IsEmailVerified = false;

                // Save to Database
                using (StudentRegEntities studentReg = new StudentRegEntities())
                {
                    studentReg.StudentLogins.Add(studentLogin);
                    studentReg.SaveChanges();

                    // Send Email to User
                    SendVerificationLinkEmail(studentLogin.Email, studentLogin.ActivationCode.ToString());
                    message = "Registration successfully done. Account activation link " +
                              " has been sent to your email id:" + studentLogin.Email;
                    Status = true;
                }
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View());
        }
Exemplo n.º 27
0
 public ActionResult Login(StudentLogin login)
 {
     if (ModelState.IsValid)
     {
         //检验验证码
         if (Session["VerificationCode"] == null || Session["VerificationCode"].ToString() == "")
         {
             Error _err = new Error {
                 Title = "验证码不存在", Details = "用户在登录时服务器端验证码为空,或向服务器提交的验证码为空"
             };
             return(RedirectToAction("Error", "Prompt", _err));
         }
         else if (Session["VerificationCode"].ToString() != login.VerificationCode.ToUpper())
         {
             ModelState.AddModelError("VerificationCode", "×");
             return(View());
         }
         //检验登录账号和密码
         DataRow dr = Student.Authenciation(login.StudentID, Common.Text.EnCrypt(login.StudentPwd));
         if (dr != null)
         {
             HttpCookie _cookie = new HttpCookie("Student");
             _cookie.Values.Add("StudentID", login.StudentID);
             _cookie.Values.Add("StudentPwd", Server.UrlEncode(Common.Text.EnCrypt(login.StudentPwd)));
             _cookie.Values.Add("StudentName", dr["StudentName"].ToString());
             Response.Cookies.Add(_cookie);
             if (Request.QueryString["ReturnUrl"] != null)
             {
                 return(Redirect(Request.QueryString["ReturnUrl"]));
             }
             else
             {
                 return(RedirectToAction("Index", "Student"));
             }
         }
         else
         {
             ModelState.AddModelError("Message", "账号或密码错误");
             return(View());
         }
     }
     return(View());
 }
        public int UpdateStudentLogin(int Id, StudentLogin studentLoginObj)
        {
            var studentLogin = _schoolDBContext.StudentLogins.Where(a => a.Id == Id).SingleOrDefault();

            if (studentLogin == null)
            {
                return(0);
            }
            else
            {
                studentLogin.Id        = studentLoginObj.Id;
                studentLogin.StudentId = studentLoginObj.StudentId;
                studentLogin.UserName  = studentLoginObj.UserName;
                studentLogin.Password  = studentLoginObj.Password;

                _schoolDBContext.SaveChanges();
                return(1);
            }
        }
Exemplo n.º 29
0
        public IActionResult RefreshToken([FromRoute] String refToken)
        {
            StudentLogin student = new StudentLogin();
            CheckToken   c       = new CheckToken();

            student = c.Check(refToken);

            if (student.refToken != null)
            {
                var claims = new[]
                {
                    new Claim(ClaimTypes.NameIdentifier, "1"),
                    new Claim(ClaimTypes.Name, "jan123"),
                    new Claim(ClaimTypes.Role, "admin"),
                    new Claim(ClaimTypes.Role, "student")
                };

                var key   = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["SecretKey"]));
                var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);

                var token = new JwtSecurityToken
                            (
                    issuer: "Gakko",
                    audience: "Students",
                    claims: claims,
                    expires: DateTime.Now.AddMinutes(10),
                    signingCredentials: creds
                            );
                SaveToken s           = new SaveToken();
                String    newRefToken = Guid.NewGuid().ToString();
                s.Save(student.IndexNumber, newRefToken);

                return(Ok(new
                {
                    token = new JwtSecurityTokenHandler().WriteToken(token),
                    newRefToken
                }
                          ));
            }
            return(StatusCode(401, "Wrong token"));
        }
        public LoginResponse GetStudentLoginPermission(StudentLogin studentLogin)
        {
            var log = _schoolDBContext.StudentLogins.Where(
                s => s.UserName.Equals(studentLogin.UserName) &&
                s.Password.Equals(studentLogin.Password)).FirstOrDefault();



            if (log == null)
            {
                return(new LoginResponse {
                    Status = "Invalid", Message = "Invalid User Name and/or Password."
                });
            }
            else
            {
                return new LoginResponse {
                           Status = "Success", Message = "Login Successful"
                }
            };
        }