Exemplo n.º 1
0
        public ServiceResponse<ServiceCredentials> RegisterNewAccount(string ServiceLRI, string DomainLRI, string Username, string passwordHash)
        {
            //get LRI from domain / username / hash
            LRI UserLRI = IDMgr.GetUserLRI(new LRI(ServiceLRI), DomainLRI, Username, passwordHash);
            if (UserLRI == null)
            {
                return new ServiceResponse<ServiceCredentials>(true);
            }
            else
            {
                if (ClientAccountLookup.ContainsKey(UserLRI))
                {
                    ServiceResponse<ServiceCredentials> Resp = new ServiceResponse<ServiceCredentials>();
                    Resp.Error = true;
                    Resp.ErrorCode = 2;
                    Resp.Message = "A user with that LRI is already registered with this system.";
                    Resp.ResponseObject = null;
                    return Resp;
                }
                else
                {
                    //we need this info
                    UserInfo info = new UserInfo();//UserManager.Identities[UserLRI.LRIString];
                    info.passwordHash = passwordHash;
                    info.Identity = IDMgr.GetUserLIdentity(new LRI(ServiceLRI), DomainLRI, Username, passwordHash);

                    //create new account and add this LRI info
                    ClientAccount Acct = new ClientAccount();
                    Acct._id = LDocumentManager.RequestGUID();
                    Acct.AccountLRI = new LRI(LCHARMSConfig.GetSection().LRI + "/" + Acct._id);
                    ClientAccountLookupByAcctID[Acct._id] = Acct;
                    AddIdentityToAccount(Acct._id, info, UserLRI);
                    //ServiceCredentials sc = new ServiceCredentials();
                    //Acct.ServiceCredentialsByLRI[userlri] =

                    //create a header for the account
                    string ID = LDocumentManager.RequestGUID();
                    LDocumentHeader NewFileHeader = new LDocumentHeader();
                    LRI hlri = new LRI(LCHARMSConfig.GetSection().LRI + "/" + ID);
                    NewFileHeader.DocType = DocumentType.DOC_HEADER;
                    NewFileHeader.DocumentID = ID;
                    NewFileHeader.FQDT = "lcharms.client.account";
                    NewFileHeader.FileName = Username.ToLower() + ".client.account";
                    NewFileHeader.DocumentLRI = hlri.ToString();
                    NewFileHeader.IsCopy = false;
                    NewFileHeader.LastAccessDate = DateTime.Now;
                    NewFileHeader.DataLength = 0;

                    //create an ACL for this new file
                    // assign it to the creation user

                    DocManager.AuthManager.CreateACE(ID, info.Identity, LDocACLPermission.GRANT |
                                        LDocACLPermission.WRITE |
                                        LDocACLPermission.READ |
                                        LDocACLPermission.ACCESS_NEXT_VERSION |
                                        LDocACLPermission.ACCESS_PREV_VERSION);
                    DocManager.AuthManager.CreateACE(ID, DocManager.AuthManager.PublicIdentity, LDocACLPermission.DENY);

                    Acct.AccountHeader = NewFileHeader;
                    SaveAccount(Acct);

                    return LoginID(UserLRI, passwordHash,false);
                }
            }
        }
Exemplo n.º 2
0
        //public bool CreateChildIdentity(string ParentLRI, string ChildUserLRI, string passwordhash, string ChildPinHash, string KeyFromChild)
        //{
        //    return true;
        //}
        //should be overloaded, called when an ID is added to save it to a persistant location
        public static void SaveIdentity(LRI userLRI)
        {
            LDocumentHeader header = LDocManager.GetDocHeader(userLRI);
            if (header == null)
            {
                //create it
                header = new LDocumentHeader();
                header.DocumentLRI = userLRI.LRIString;
                header.FQDT = "lcharms.user";
                header.DocumentID = userLRI.DocumentID;
                header.DocType = DocumentType.DOC_HEADER;
                List<LDocumentPart> parts = new List<LDocumentPart>();
                LDocumentPart idPart = new LDocumentPart();
                idPart.DocumentID = userLRI.DocumentID;
                idPart.SequenceNumber = 0;
                idPart.DocType = DocumentType.DOC_PART;
                parts.Add(idPart);
                LDocManager.CreateDoc(userLRI, header, parts);
            }
            else
            {

            }
            //CouchDBMgr.WriteDocument(userLRI.DocumentID, Identities[userLRI.LRIString]);
        }