Beispiel #1
0
        public static dynamic CreateSession(string userName, string password, string connectionId)
        {
            try {
                bool hasManySessions = false;
                var session = new Session {
                    UserName = userName,
                    ConnectionId = connectionId,
                    Password = password
                };
                var ctx = Proxy.Connect("kodemo");
                ctx.Sessions.Insert(session);
                var match = ctx.Users.FindByUserName(userName);
                //Check if user has many sessions open
                var query = ctx.Sessions.FindAllByUserName(userName);
                if (query != null)
                    hasManySessions = query.ToList().Count > 1;

                if(match == null && !string.IsNullOrWhiteSpace(password))
                    ctx.Users.Insert(new {
                        UserName = session.UserName,
                        Password = session.Password,
                        DateCreated = DateTime.Now.ToString()
                    });

                return new {
                    UserName = userName,
                    hasManyOpenSessions = hasManySessions
                };

            } catch{
                return null;
            }
        }
Beispiel #2
0
 public void CreateUserSession(Session chatSession)
 {
     var result = UserBroker.CreateSession(chatSession.UserName, chatSession.Password, Context.ConnectionId);
     if(result != null &&  !string.IsNullOrEmpty(chatSession.UserName)){
          Clients[Context.ConnectionId].setCredentials(chatSession.UserName);
          Clients[Context.ConnectionId].sendMeMessage("System: ", "Your session was successfully created");
         if(!result.hasManyOpenSessions)
             Clients.broadcast(string.Format("{0} just joined the chat room",chatSession.UserName));
     }else{
         Clients[Context.ConnectionId].sendMeMessage("System", "Error creating your session");
     }
 }
Beispiel #3
0
        public static bool SigIn(Session session)
        {
            var ctx = Proxy.Connect("kodemo");
            try {
                var match = ctx.Users.FindByUserName(session.UserName);
                if (match == null)
                    return false;
                else
                    return ((Session)match).Password.Equals(session.Password);

            } catch{
                return false;
            }
        }
Beispiel #4
0
 public void SignIn(Session chatSession)
 {
     var success = UserBroker.SigIn(chatSession);
     if (success)
         CreateUserSession(chatSession);
 }